<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Source code</title>
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
</head>
<body>
<div class="sourceContainer">
<pre><span class="sourceLineNo">001</span>/*<a name="line.1"></a>
<span class="sourceLineNo">002</span> * Licensed to the Apache Software Foundation (ASF) under one or more<a name="line.2"></a>
<span class="sourceLineNo">003</span> * contributor license agreements.  See the NOTICE file distributed with<a name="line.3"></a>
<span class="sourceLineNo">004</span> * this work for additional information regarding copyright ownership.<a name="line.4"></a>
<span class="sourceLineNo">005</span> * The ASF licenses this file to You under the Apache License, Version 2.0<a name="line.5"></a>
<span class="sourceLineNo">006</span> * (the "License"); you may not use this file except in compliance with<a name="line.6"></a>
<span class="sourceLineNo">007</span> * the License.  You may obtain a copy of the License at<a name="line.7"></a>
<span class="sourceLineNo">008</span> *<a name="line.8"></a>
<span class="sourceLineNo">009</span> *      http://www.apache.org/licenses/LICENSE-2.0<a name="line.9"></a>
<span class="sourceLineNo">010</span> *<a name="line.10"></a>
<span class="sourceLineNo">011</span> * Unless required by applicable law or agreed to in writing, software<a name="line.11"></a>
<span class="sourceLineNo">012</span> * distributed under the License is distributed on an "AS IS" BASIS,<a name="line.12"></a>
<span class="sourceLineNo">013</span> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<a name="line.13"></a>
<span class="sourceLineNo">014</span> * See the License for the specific language governing permissions and<a name="line.14"></a>
<span class="sourceLineNo">015</span> * limitations under the License.<a name="line.15"></a>
<span class="sourceLineNo">016</span> */<a name="line.16"></a>
<span class="sourceLineNo">017</span>package org.apache.commons.net.ftp;<a name="line.17"></a>
<span class="sourceLineNo">018</span>import java.io.BufferedInputStream;<a name="line.18"></a>
<span class="sourceLineNo">019</span>import java.io.BufferedOutputStream;<a name="line.19"></a>
<span class="sourceLineNo">020</span>import java.io.BufferedReader;<a name="line.20"></a>
<span class="sourceLineNo">021</span>import java.io.BufferedWriter;<a name="line.21"></a>
<span class="sourceLineNo">022</span>import java.io.IOException;<a name="line.22"></a>
<span class="sourceLineNo">023</span>import java.io.InputStream;<a name="line.23"></a>
<span class="sourceLineNo">024</span>import java.io.InputStreamReader;<a name="line.24"></a>
<span class="sourceLineNo">025</span>import java.io.OutputStream;<a name="line.25"></a>
<span class="sourceLineNo">026</span>import java.io.OutputStreamWriter;<a name="line.26"></a>
<span class="sourceLineNo">027</span>import java.net.Inet6Address;<a name="line.27"></a>
<span class="sourceLineNo">028</span>import java.net.InetAddress;<a name="line.28"></a>
<span class="sourceLineNo">029</span>import java.net.InetSocketAddress;<a name="line.29"></a>
<span class="sourceLineNo">030</span>import java.net.ServerSocket;<a name="line.30"></a>
<span class="sourceLineNo">031</span>import java.net.Socket;<a name="line.31"></a>
<span class="sourceLineNo">032</span>import java.net.SocketException;<a name="line.32"></a>
<span class="sourceLineNo">033</span>import java.net.SocketTimeoutException;<a name="line.33"></a>
<span class="sourceLineNo">034</span>import java.net.UnknownHostException;<a name="line.34"></a>
<span class="sourceLineNo">035</span>import java.util.ArrayList;<a name="line.35"></a>
<span class="sourceLineNo">036</span>import java.util.HashMap;<a name="line.36"></a>
<span class="sourceLineNo">037</span>import java.util.HashSet;<a name="line.37"></a>
<span class="sourceLineNo">038</span>import java.util.Locale;<a name="line.38"></a>
<span class="sourceLineNo">039</span>import java.util.Properties;<a name="line.39"></a>
<span class="sourceLineNo">040</span>import java.util.Random;<a name="line.40"></a>
<span class="sourceLineNo">041</span>import java.util.Set;<a name="line.41"></a>
<span class="sourceLineNo">042</span><a name="line.42"></a>
<span class="sourceLineNo">043</span>import org.apache.commons.net.MalformedServerReplyException;<a name="line.43"></a>
<span class="sourceLineNo">044</span>import org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory;<a name="line.44"></a>
<span class="sourceLineNo">045</span>import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory;<a name="line.45"></a>
<span class="sourceLineNo">046</span>import org.apache.commons.net.ftp.parser.MLSxEntryParser;<a name="line.46"></a>
<span class="sourceLineNo">047</span>import org.apache.commons.net.io.CRLFLineReader;<a name="line.47"></a>
<span class="sourceLineNo">048</span>import org.apache.commons.net.io.CopyStreamAdapter;<a name="line.48"></a>
<span class="sourceLineNo">049</span>import org.apache.commons.net.io.CopyStreamEvent;<a name="line.49"></a>
<span class="sourceLineNo">050</span>import org.apache.commons.net.io.CopyStreamListener;<a name="line.50"></a>
<span class="sourceLineNo">051</span>import org.apache.commons.net.io.FromNetASCIIInputStream;<a name="line.51"></a>
<span class="sourceLineNo">052</span>import org.apache.commons.net.io.ToNetASCIIOutputStream;<a name="line.52"></a>
<span class="sourceLineNo">053</span>import org.apache.commons.net.io.Util;<a name="line.53"></a>
<span class="sourceLineNo">054</span><a name="line.54"></a>
<span class="sourceLineNo">055</span>/**<a name="line.55"></a>
<span class="sourceLineNo">056</span> * FTPClient encapsulates all the functionality necessary to store and<a name="line.56"></a>
<span class="sourceLineNo">057</span> * retrieve files from an FTP server.  This class takes care of all<a name="line.57"></a>
<span class="sourceLineNo">058</span> * low level details of interacting with an FTP server and provides<a name="line.58"></a>
<span class="sourceLineNo">059</span> * a convenient higher level interface.  As with all classes derived<a name="line.59"></a>
<span class="sourceLineNo">060</span> * from {@link org.apache.commons.net.SocketClient},<a name="line.60"></a>
<span class="sourceLineNo">061</span> * you must first connect to the server with<a name="line.61"></a>
<span class="sourceLineNo">062</span> * {@link org.apache.commons.net.SocketClient#connect  connect }<a name="line.62"></a>
<span class="sourceLineNo">063</span> * before doing anything, and finally<a name="line.63"></a>
<span class="sourceLineNo">064</span> * {@link org.apache.commons.net.SocketClient#disconnect  disconnect }<a name="line.64"></a>
<span class="sourceLineNo">065</span> * after you're completely finished interacting with the server.<a name="line.65"></a>
<span class="sourceLineNo">066</span> * Then you need to check the FTP reply code to see if the connection<a name="line.66"></a>
<span class="sourceLineNo">067</span> * was successful.  For example:<a name="line.67"></a>
<span class="sourceLineNo">068</span> * &lt;pre&gt;<a name="line.68"></a>
<span class="sourceLineNo">069</span> *    FTPClient ftp = new FTPClient();<a name="line.69"></a>
<span class="sourceLineNo">070</span> *    FTPClientConfig config = new FTPClientConfig();<a name="line.70"></a>
<span class="sourceLineNo">071</span> *    config.setXXX(YYY); // change required options<a name="line.71"></a>
<span class="sourceLineNo">072</span> *    ftp.configure(config );<a name="line.72"></a>
<span class="sourceLineNo">073</span> *    boolean error = false;<a name="line.73"></a>
<span class="sourceLineNo">074</span> *    try {<a name="line.74"></a>
<span class="sourceLineNo">075</span> *      int reply;<a name="line.75"></a>
<span class="sourceLineNo">076</span> *      ftp.connect("ftp.foobar.com");<a name="line.76"></a>
<span class="sourceLineNo">077</span> *      System.out.println("Connected to " + server + ".");<a name="line.77"></a>
<span class="sourceLineNo">078</span> *      System.out.print(ftp.getReplyString());<a name="line.78"></a>
<span class="sourceLineNo">079</span> *<a name="line.79"></a>
<span class="sourceLineNo">080</span> *      // After connection attempt, you should check the reply code to verify<a name="line.80"></a>
<span class="sourceLineNo">081</span> *      // success.<a name="line.81"></a>
<span class="sourceLineNo">082</span> *      reply = ftp.getReplyCode();<a name="line.82"></a>
<span class="sourceLineNo">083</span> *<a name="line.83"></a>
<span class="sourceLineNo">084</span> *      if(!FTPReply.isPositiveCompletion(reply)) {<a name="line.84"></a>
<span class="sourceLineNo">085</span> *        ftp.disconnect();<a name="line.85"></a>
<span class="sourceLineNo">086</span> *        System.err.println("FTP server refused connection.");<a name="line.86"></a>
<span class="sourceLineNo">087</span> *        System.exit(1);<a name="line.87"></a>
<span class="sourceLineNo">088</span> *      }<a name="line.88"></a>
<span class="sourceLineNo">089</span> *      ... // transfer files<a name="line.89"></a>
<span class="sourceLineNo">090</span> *      ftp.logout();<a name="line.90"></a>
<span class="sourceLineNo">091</span> *    } catch(IOException e) {<a name="line.91"></a>
<span class="sourceLineNo">092</span> *      error = true;<a name="line.92"></a>
<span class="sourceLineNo">093</span> *      e.printStackTrace();<a name="line.93"></a>
<span class="sourceLineNo">094</span> *    } finally {<a name="line.94"></a>
<span class="sourceLineNo">095</span> *      if(ftp.isConnected()) {<a name="line.95"></a>
<span class="sourceLineNo">096</span> *        try {<a name="line.96"></a>
<span class="sourceLineNo">097</span> *          ftp.disconnect();<a name="line.97"></a>
<span class="sourceLineNo">098</span> *        } catch(IOException ioe) {<a name="line.98"></a>
<span class="sourceLineNo">099</span> *          // do nothing<a name="line.99"></a>
<span class="sourceLineNo">100</span> *        }<a name="line.100"></a>
<span class="sourceLineNo">101</span> *      }<a name="line.101"></a>
<span class="sourceLineNo">102</span> *      System.exit(error ? 1 : 0);<a name="line.102"></a>
<span class="sourceLineNo">103</span> *    }<a name="line.103"></a>
<span class="sourceLineNo">104</span> * &lt;/pre&gt;<a name="line.104"></a>
<span class="sourceLineNo">105</span> * &lt;p&gt;<a name="line.105"></a>
<span class="sourceLineNo">106</span> * Immediately after connecting is the only real time you need to check the<a name="line.106"></a>
<span class="sourceLineNo">107</span> * reply code (because connect is of type void).  The convention for all the<a name="line.107"></a>
<span class="sourceLineNo">108</span> * FTP command methods in FTPClient is such that they either return a<a name="line.108"></a>
<span class="sourceLineNo">109</span> * boolean value or some other value.<a name="line.109"></a>
<span class="sourceLineNo">110</span> * The boolean methods return true on a successful completion reply from<a name="line.110"></a>
<span class="sourceLineNo">111</span> * the FTP server and false on a reply resulting in an error condition or<a name="line.111"></a>
<span class="sourceLineNo">112</span> * failure.  The methods returning a value other than boolean return a value<a name="line.112"></a>
<span class="sourceLineNo">113</span> * containing the higher level data produced by the FTP command, or null if a<a name="line.113"></a>
<span class="sourceLineNo">114</span> * reply resulted in an error condition or failure.  If you want to access<a name="line.114"></a>
<span class="sourceLineNo">115</span> * the exact FTP reply code causing a success or failure, you must call<a name="line.115"></a>
<span class="sourceLineNo">116</span> * {@link org.apache.commons.net.ftp.FTP#getReplyCode  getReplyCode } after<a name="line.116"></a>
<span class="sourceLineNo">117</span> * a success or failure.<a name="line.117"></a>
<span class="sourceLineNo">118</span> * &lt;p&gt;<a name="line.118"></a>
<span class="sourceLineNo">119</span> * The default settings for FTPClient are for it to use<a name="line.119"></a>
<span class="sourceLineNo">120</span> * &lt;code&gt; FTP.ASCII_FILE_TYPE &lt;/code&gt;,<a name="line.120"></a>
<span class="sourceLineNo">121</span> * &lt;code&gt; FTP.NON_PRINT_TEXT_FORMAT &lt;/code&gt;,<a name="line.121"></a>
<span class="sourceLineNo">122</span> * &lt;code&gt; FTP.STREAM_TRANSFER_MODE &lt;/code&gt;, and<a name="line.122"></a>
<span class="sourceLineNo">123</span> * &lt;code&gt; FTP.FILE_STRUCTURE &lt;/code&gt;.  The only file types directly supported<a name="line.123"></a>
<span class="sourceLineNo">124</span> * are &lt;code&gt; FTP.ASCII_FILE_TYPE &lt;/code&gt; and<a name="line.124"></a>
<span class="sourceLineNo">125</span> * &lt;code&gt; FTP.BINARY_FILE_TYPE &lt;/code&gt;.  Because there are at least 4<a name="line.125"></a>
<span class="sourceLineNo">126</span> * different EBCDIC encodings, we have opted not to provide direct support<a name="line.126"></a>
<span class="sourceLineNo">127</span> * for EBCDIC.  To transfer EBCDIC and other unsupported file types you<a name="line.127"></a>
<span class="sourceLineNo">128</span> * must create your own filter InputStreams and OutputStreams and wrap<a name="line.128"></a>
<span class="sourceLineNo">129</span> * them around the streams returned or required by the FTPClient methods.<a name="line.129"></a>
<span class="sourceLineNo">130</span> * FTPClient uses the {@link ToNetASCIIOutputStream NetASCII}<a name="line.130"></a>
<span class="sourceLineNo">131</span> * filter streams to provide transparent handling of ASCII files.  We will<a name="line.131"></a>
<span class="sourceLineNo">132</span> * consider incorporating EBCDIC support if there is enough demand.<a name="line.132"></a>
<span class="sourceLineNo">133</span> * &lt;p&gt;<a name="line.133"></a>
<span class="sourceLineNo">134</span> * &lt;code&gt; FTP.NON_PRINT_TEXT_FORMAT &lt;/code&gt;,<a name="line.134"></a>
<span class="sourceLineNo">135</span> * &lt;code&gt; FTP.STREAM_TRANSFER_MODE &lt;/code&gt;, and<a name="line.135"></a>
<span class="sourceLineNo">136</span> * &lt;code&gt; FTP.FILE_STRUCTURE &lt;/code&gt; are the only supported formats,<a name="line.136"></a>
<span class="sourceLineNo">137</span> * transfer modes, and file structures.<a name="line.137"></a>
<span class="sourceLineNo">138</span> * &lt;p&gt;<a name="line.138"></a>
<span class="sourceLineNo">139</span> * Because the handling of sockets on different platforms can differ<a name="line.139"></a>
<span class="sourceLineNo">140</span> * significantly, the FTPClient automatically issues a new PORT (or EPRT) command<a name="line.140"></a>
<span class="sourceLineNo">141</span> * prior to every transfer requiring that the server connect to the client's<a name="line.141"></a>
<span class="sourceLineNo">142</span> * data port.  This ensures identical problem-free behavior on Windows, Unix,<a name="line.142"></a>
<span class="sourceLineNo">143</span> * and Macintosh platforms.  Additionally, it relieves programmers from<a name="line.143"></a>
<span class="sourceLineNo">144</span> * having to issue the PORT (or EPRT) command themselves and dealing with platform<a name="line.144"></a>
<span class="sourceLineNo">145</span> * dependent issues.<a name="line.145"></a>
<span class="sourceLineNo">146</span> * &lt;p&gt;<a name="line.146"></a>
<span class="sourceLineNo">147</span> * Additionally, for security purposes, all data connections to the<a name="line.147"></a>
<span class="sourceLineNo">148</span> * client are verified to ensure that they originated from the intended<a name="line.148"></a>
<span class="sourceLineNo">149</span> * party (host and port).  If a data connection is initiated by an unexpected<a name="line.149"></a>
<span class="sourceLineNo">150</span> * party, the command will close the socket and throw an IOException.  You<a name="line.150"></a>
<span class="sourceLineNo">151</span> * may disable this behavior with<a name="line.151"></a>
<span class="sourceLineNo">152</span> * {@link #setRemoteVerificationEnabled setRemoteVerificationEnabled()}.<a name="line.152"></a>
<span class="sourceLineNo">153</span> * &lt;p&gt;<a name="line.153"></a>
<span class="sourceLineNo">154</span> * You should keep in mind that the FTP server may choose to prematurely<a name="line.154"></a>
<span class="sourceLineNo">155</span> * close a connection if the client has been idle for longer than a<a name="line.155"></a>
<span class="sourceLineNo">156</span> * given time period (usually 900 seconds).  The FTPClient class will detect a<a name="line.156"></a>
<span class="sourceLineNo">157</span> * premature FTP server connection closing when it receives a<a name="line.157"></a>
<span class="sourceLineNo">158</span> * {@link org.apache.commons.net.ftp.FTPReply#SERVICE_NOT_AVAILABLE FTPReply.SERVICE_NOT_AVAILABLE }<a name="line.158"></a>
<span class="sourceLineNo">159</span> *  response to a command.<a name="line.159"></a>
<span class="sourceLineNo">160</span> * When that occurs, the FTP class method encountering that reply will throw<a name="line.160"></a>
<span class="sourceLineNo">161</span> * an {@link org.apache.commons.net.ftp.FTPConnectionClosedException}<a name="line.161"></a>
<span class="sourceLineNo">162</span> * .<a name="line.162"></a>
<span class="sourceLineNo">163</span> * &lt;code&gt;FTPConnectionClosedException&lt;/code&gt;<a name="line.163"></a>
<span class="sourceLineNo">164</span> * is a subclass of &lt;code&gt; IOException &lt;/code&gt; and therefore need not be<a name="line.164"></a>
<span class="sourceLineNo">165</span> * caught separately, but if you are going to catch it separately, its<a name="line.165"></a>
<span class="sourceLineNo">166</span> * catch block must appear before the more general &lt;code&gt; IOException &lt;/code&gt;<a name="line.166"></a>
<span class="sourceLineNo">167</span> * catch block.  When you encounter an<a name="line.167"></a>
<span class="sourceLineNo">168</span> * {@link org.apache.commons.net.ftp.FTPConnectionClosedException}<a name="line.168"></a>
<span class="sourceLineNo">169</span> * , you must disconnect the connection with<a name="line.169"></a>
<span class="sourceLineNo">170</span> * {@link #disconnect  disconnect() } to properly clean up the<a name="line.170"></a>
<span class="sourceLineNo">171</span> * system resources used by FTPClient.  Before disconnecting, you may check the<a name="line.171"></a>
<span class="sourceLineNo">172</span> * last reply code and text with<a name="line.172"></a>
<span class="sourceLineNo">173</span> * {@link org.apache.commons.net.ftp.FTP#getReplyCode  getReplyCode },<a name="line.173"></a>
<span class="sourceLineNo">174</span> * {@link org.apache.commons.net.ftp.FTP#getReplyString  getReplyString },<a name="line.174"></a>
<span class="sourceLineNo">175</span> * and<a name="line.175"></a>
<span class="sourceLineNo">176</span> * {@link org.apache.commons.net.ftp.FTP#getReplyStrings  getReplyStrings}.<a name="line.176"></a>
<span class="sourceLineNo">177</span> * You may avoid server disconnections while the client is idle by<a name="line.177"></a>
<span class="sourceLineNo">178</span> * periodically sending NOOP commands to the server.<a name="line.178"></a>
<span class="sourceLineNo">179</span> * &lt;p&gt;<a name="line.179"></a>
<span class="sourceLineNo">180</span> * Rather than list it separately for each method, we mention here that<a name="line.180"></a>
<span class="sourceLineNo">181</span> * every method communicating with the server and throwing an IOException<a name="line.181"></a>
<span class="sourceLineNo">182</span> * can also throw a<a name="line.182"></a>
<span class="sourceLineNo">183</span> * {@link org.apache.commons.net.MalformedServerReplyException}<a name="line.183"></a>
<span class="sourceLineNo">184</span> * , which is a subclass<a name="line.184"></a>
<span class="sourceLineNo">185</span> * of IOException.  A MalformedServerReplyException will be thrown when<a name="line.185"></a>
<span class="sourceLineNo">186</span> * the reply received from the server deviates enough from the protocol<a name="line.186"></a>
<span class="sourceLineNo">187</span> * specification that it cannot be interpreted in a useful manner despite<a name="line.187"></a>
<span class="sourceLineNo">188</span> * attempts to be as lenient as possible.<a name="line.188"></a>
<span class="sourceLineNo">189</span> * &lt;p&gt;<a name="line.189"></a>
<span class="sourceLineNo">190</span> * Listing API Examples<a name="line.190"></a>
<span class="sourceLineNo">191</span> * Both paged and unpaged examples of directory listings are available,<a name="line.191"></a>
<span class="sourceLineNo">192</span> * as follows:<a name="line.192"></a>
<span class="sourceLineNo">193</span> * &lt;p&gt;<a name="line.193"></a>
<span class="sourceLineNo">194</span> * Unpaged (whole list) access, using a parser accessible by auto-detect:<a name="line.194"></a>
<span class="sourceLineNo">195</span> * &lt;pre&gt;<a name="line.195"></a>
<span class="sourceLineNo">196</span> *    FTPClient f = new FTPClient();<a name="line.196"></a>
<span class="sourceLineNo">197</span> *    f.connect(server);<a name="line.197"></a>
<span class="sourceLineNo">198</span> *    f.login(username, password);<a name="line.198"></a>
<span class="sourceLineNo">199</span> *    FTPFile[] files = f.listFiles(directory);<a name="line.199"></a>
<span class="sourceLineNo">200</span> * &lt;/pre&gt;<a name="line.200"></a>
<span class="sourceLineNo">201</span> * &lt;p&gt;<a name="line.201"></a>
<span class="sourceLineNo">202</span> * Paged access, using a parser not accessible by auto-detect.  The class<a name="line.202"></a>
<span class="sourceLineNo">203</span> * defined in the first parameter of initateListParsing should be derived<a name="line.203"></a>
<span class="sourceLineNo">204</span> * from org.apache.commons.net.FTPFileEntryParser:<a name="line.204"></a>
<span class="sourceLineNo">205</span> * &lt;pre&gt;<a name="line.205"></a>
<span class="sourceLineNo">206</span> *    FTPClient f = new FTPClient();<a name="line.206"></a>
<span class="sourceLineNo">207</span> *    f.connect(server);<a name="line.207"></a>
<span class="sourceLineNo">208</span> *    f.login(username, password);<a name="line.208"></a>
<span class="sourceLineNo">209</span> *    FTPListParseEngine engine =<a name="line.209"></a>
<span class="sourceLineNo">210</span> *       f.initiateListParsing("com.whatever.YourOwnParser", directory);<a name="line.210"></a>
<span class="sourceLineNo">211</span> *<a name="line.211"></a>
<span class="sourceLineNo">212</span> *    while (engine.hasNext()) {<a name="line.212"></a>
<span class="sourceLineNo">213</span> *       FTPFile[] files = engine.getNext(25);  // "page size" you want<a name="line.213"></a>
<span class="sourceLineNo">214</span> *       //do whatever you want with these files, display them, etc.<a name="line.214"></a>
<span class="sourceLineNo">215</span> *       //expensive FTPFile objects not created until needed.<a name="line.215"></a>
<span class="sourceLineNo">216</span> *    }<a name="line.216"></a>
<span class="sourceLineNo">217</span> * &lt;/pre&gt;<a name="line.217"></a>
<span class="sourceLineNo">218</span> * &lt;p&gt;<a name="line.218"></a>
<span class="sourceLineNo">219</span> * Paged access, using a parser accessible by auto-detect:<a name="line.219"></a>
<span class="sourceLineNo">220</span> * &lt;pre&gt;<a name="line.220"></a>
<span class="sourceLineNo">221</span> *    FTPClient f = new FTPClient();<a name="line.221"></a>
<span class="sourceLineNo">222</span> *    f.connect(server);<a name="line.222"></a>
<span class="sourceLineNo">223</span> *    f.login(username, password);<a name="line.223"></a>
<span class="sourceLineNo">224</span> *    FTPListParseEngine engine = f.initiateListParsing(directory);<a name="line.224"></a>
<span class="sourceLineNo">225</span> *<a name="line.225"></a>
<span class="sourceLineNo">226</span> *    while (engine.hasNext()) {<a name="line.226"></a>
<span class="sourceLineNo">227</span> *       FTPFile[] files = engine.getNext(25);  // "page size" you want<a name="line.227"></a>
<span class="sourceLineNo">228</span> *       //do whatever you want with these files, display them, etc.<a name="line.228"></a>
<span class="sourceLineNo">229</span> *       //expensive FTPFile objects not created until needed.<a name="line.229"></a>
<span class="sourceLineNo">230</span> *    }<a name="line.230"></a>
<span class="sourceLineNo">231</span> * &lt;/pre&gt;<a name="line.231"></a>
<span class="sourceLineNo">232</span> * &lt;p&gt;<a name="line.232"></a>
<span class="sourceLineNo">233</span> * For examples of using FTPClient on servers whose directory listings<a name="line.233"></a>
<span class="sourceLineNo">234</span> * &lt;ul&gt;<a name="line.234"></a>
<span class="sourceLineNo">235</span> * &lt;li&gt;use languages other than English&lt;/li&gt;<a name="line.235"></a>
<span class="sourceLineNo">236</span> * &lt;li&gt;use date formats other than the American English "standard" &lt;code&gt;MM d yyyy&lt;/code&gt;&lt;/li&gt;<a name="line.236"></a>
<span class="sourceLineNo">237</span> * &lt;li&gt;are in different timezones and you need accurate timestamps for dependency checking<a name="line.237"></a>
<span class="sourceLineNo">238</span> *     as in Ant&lt;/li&gt;<a name="line.238"></a>
<span class="sourceLineNo">239</span> * &lt;/ul&gt;see {@link  FTPClientConfig  FTPClientConfig}.<a name="line.239"></a>
<span class="sourceLineNo">240</span> * &lt;p&gt;<a name="line.240"></a>
<span class="sourceLineNo">241</span> * &lt;b&gt;Control channel keep-alive feature&lt;/b&gt;:&lt;br/&gt;<a name="line.241"></a>
<span class="sourceLineNo">242</span> * During file transfers, the data connection is busy, but the control connection is idle.<a name="line.242"></a>
<span class="sourceLineNo">243</span> * FTP servers know that the control connection is in use, so won't close it through lack of activity,<a name="line.243"></a>
<span class="sourceLineNo">244</span> * but it's a lot harder for network routers to know that the control and data connections are associated<a name="line.244"></a>
<span class="sourceLineNo">245</span> * with each other.<a name="line.245"></a>
<span class="sourceLineNo">246</span> * Some routers may treat the control connection as idle, and disconnect it if the transfer over the data<a name="line.246"></a>
<span class="sourceLineNo">247</span> * connection takes longer than the allowable idle time for the router.<a name="line.247"></a>
<span class="sourceLineNo">248</span> * &lt;br/&gt;<a name="line.248"></a>
<span class="sourceLineNo">249</span> * One solution to this is to send a safe command (i.e. NOOP) over the control connection to reset the router's<a name="line.249"></a>
<span class="sourceLineNo">250</span> * idle timer. This is enabled as follows:<a name="line.250"></a>
<span class="sourceLineNo">251</span> * &lt;pre&gt;<a name="line.251"></a>
<span class="sourceLineNo">252</span> *     ftpClient.setControlKeepAliveTimeout(300); // set timeout to 5 minutes<a name="line.252"></a>
<span class="sourceLineNo">253</span> * &lt;/pre&gt;<a name="line.253"></a>
<span class="sourceLineNo">254</span> * This will cause the file upload/download methods to send a NOOP approximately every 5 minutes.<a name="line.254"></a>
<span class="sourceLineNo">255</span> * &lt;p&gt;<a name="line.255"></a>
<span class="sourceLineNo">256</span> * The implementation currently uses a {@link CopyStreamListener} which is passed to the<a name="line.256"></a>
<span class="sourceLineNo">257</span> * {@link Util#copyStream(InputStream, OutputStream, int, long, CopyStreamListener, boolean)}<a name="line.257"></a>
<span class="sourceLineNo">258</span> * method, so the timing is partially dependent on how long each block transfer takes.<a name="line.258"></a>
<span class="sourceLineNo">259</span> * &lt;p&gt;<a name="line.259"></a>
<span class="sourceLineNo">260</span> * &lt;b&gt;Note:&lt;/b&gt; this does not apply to the methods where the user is responsible for writing or reading<a name="line.260"></a>
<span class="sourceLineNo">261</span> * the data stream, i.e. {@link #retrieveFileStream(String)} , {@link #storeFileStream(String)}<a name="line.261"></a>
<span class="sourceLineNo">262</span> * and the other xxxFileStream methods<a name="line.262"></a>
<span class="sourceLineNo">263</span> * &lt;p&gt;<a name="line.263"></a>
<span class="sourceLineNo">264</span> *<a name="line.264"></a>
<span class="sourceLineNo">265</span> * @see #FTP_SYSTEM_TYPE<a name="line.265"></a>
<span class="sourceLineNo">266</span> * @see #SYSTEM_TYPE_PROPERTIES<a name="line.266"></a>
<span class="sourceLineNo">267</span> * @see FTP<a name="line.267"></a>
<span class="sourceLineNo">268</span> * @see FTPConnectionClosedException<a name="line.268"></a>
<span class="sourceLineNo">269</span> * @see FTPFileEntryParser<a name="line.269"></a>
<span class="sourceLineNo">270</span> * @see FTPFileEntryParserFactory<a name="line.270"></a>
<span class="sourceLineNo">271</span> * @see DefaultFTPFileEntryParserFactory<a name="line.271"></a>
<span class="sourceLineNo">272</span> * @see FTPClientConfig<a name="line.272"></a>
<span class="sourceLineNo">273</span> *<a name="line.273"></a>
<span class="sourceLineNo">274</span> * @see org.apache.commons.net.MalformedServerReplyException<a name="line.274"></a>
<span class="sourceLineNo">275</span> */<a name="line.275"></a>
<span class="sourceLineNo">276</span>public class FTPClient extends FTP<a name="line.276"></a>
<span class="sourceLineNo">277</span>implements Configurable<a name="line.277"></a>
<span class="sourceLineNo">278</span>{<a name="line.278"></a>
<span class="sourceLineNo">279</span>    /**<a name="line.279"></a>
<span class="sourceLineNo">280</span>     * The system property ({@value}) which can be used to override the system type.&lt;br/&gt;<a name="line.280"></a>
<span class="sourceLineNo">281</span>     * If defined, the value will be used to create any automatically created parsers.<a name="line.281"></a>
<span class="sourceLineNo">282</span>     *<a name="line.282"></a>
<span class="sourceLineNo">283</span>     * @since 3.0<a name="line.283"></a>
<span class="sourceLineNo">284</span>     */<a name="line.284"></a>
<span class="sourceLineNo">285</span>    public static final String FTP_SYSTEM_TYPE = "org.apache.commons.net.ftp.systemType";<a name="line.285"></a>
<span class="sourceLineNo">286</span><a name="line.286"></a>
<span class="sourceLineNo">287</span>    /**<a name="line.287"></a>
<span class="sourceLineNo">288</span>     * The system property ({@value}) which can be used as the default system type.&lt;br/&gt;<a name="line.288"></a>
<span class="sourceLineNo">289</span>     * If defined, the value will be used if the SYST command fails.<a name="line.289"></a>
<span class="sourceLineNo">290</span>     *<a name="line.290"></a>
<span class="sourceLineNo">291</span>     * @since 3.1<a name="line.291"></a>
<span class="sourceLineNo">292</span>     */<a name="line.292"></a>
<span class="sourceLineNo">293</span>    public static final String FTP_SYSTEM_TYPE_DEFAULT = "org.apache.commons.net.ftp.systemType.default";<a name="line.293"></a>
<span class="sourceLineNo">294</span><a name="line.294"></a>
<span class="sourceLineNo">295</span>    /**<a name="line.295"></a>
<span class="sourceLineNo">296</span>     * The name of an optional systemType properties file ({@value}), which is loaded<a name="line.296"></a>
<span class="sourceLineNo">297</span>     * using {@link Class#getResourceAsStream(String)}.&lt;br/&gt;<a name="line.297"></a>
<span class="sourceLineNo">298</span>     * The entries are the systemType (as determined by {@link FTPClient#getSystemType})<a name="line.298"></a>
<span class="sourceLineNo">299</span>     * and the values are the replacement type or parserClass, which is passed to<a name="line.299"></a>
<span class="sourceLineNo">300</span>     * {@link FTPFileEntryParserFactory#createFileEntryParser(String)}.&lt;br/&gt;<a name="line.300"></a>
<span class="sourceLineNo">301</span>     * For example:<a name="line.301"></a>
<span class="sourceLineNo">302</span>     * &lt;pre&gt;<a name="line.302"></a>
<span class="sourceLineNo">303</span>     * Plan 9=Unix<a name="line.303"></a>
<span class="sourceLineNo">304</span>     * OS410=org.apache.commons.net.ftp.parser.OS400FTPEntryParser<a name="line.304"></a>
<span class="sourceLineNo">305</span>     * &lt;/pre&gt;<a name="line.305"></a>
<span class="sourceLineNo">306</span>     *<a name="line.306"></a>
<span class="sourceLineNo">307</span>     * @since 3.0<a name="line.307"></a>
<span class="sourceLineNo">308</span>     */<a name="line.308"></a>
<span class="sourceLineNo">309</span>    public static final String SYSTEM_TYPE_PROPERTIES = "/systemType.properties";<a name="line.309"></a>
<span class="sourceLineNo">310</span><a name="line.310"></a>
<span class="sourceLineNo">311</span>    /**<a name="line.311"></a>
<span class="sourceLineNo">312</span>     * A constant indicating the FTP session is expecting all transfers<a name="line.312"></a>
<span class="sourceLineNo">313</span>     * to occur between the client (local) and server and that the server<a name="line.313"></a>
<span class="sourceLineNo">314</span>     * should connect to the client's data port to initiate a data transfer.<a name="line.314"></a>
<span class="sourceLineNo">315</span>     * This is the default data connection mode when and FTPClient instance<a name="line.315"></a>
<span class="sourceLineNo">316</span>     * is created.<a name="line.316"></a>
<span class="sourceLineNo">317</span>     */<a name="line.317"></a>
<span class="sourceLineNo">318</span>    public static final int ACTIVE_LOCAL_DATA_CONNECTION_MODE = 0;<a name="line.318"></a>
<span class="sourceLineNo">319</span>    /**<a name="line.319"></a>
<span class="sourceLineNo">320</span>     * A constant indicating the FTP session is expecting all transfers<a name="line.320"></a>
<span class="sourceLineNo">321</span>     * to occur between two remote servers and that the server<a name="line.321"></a>
<span class="sourceLineNo">322</span>     * the client is connected to should connect to the other server's<a name="line.322"></a>
<span class="sourceLineNo">323</span>     * data port to initiate a data transfer.<a name="line.323"></a>
<span class="sourceLineNo">324</span>     */<a name="line.324"></a>
<span class="sourceLineNo">325</span>    public static final int ACTIVE_REMOTE_DATA_CONNECTION_MODE = 1;<a name="line.325"></a>
<span class="sourceLineNo">326</span>    /**<a name="line.326"></a>
<span class="sourceLineNo">327</span>     * A constant indicating the FTP session is expecting all transfers<a name="line.327"></a>
<span class="sourceLineNo">328</span>     * to occur between the client (local) and server and that the server<a name="line.328"></a>
<span class="sourceLineNo">329</span>     * is in passive mode, requiring the client to connect to the<a name="line.329"></a>
<span class="sourceLineNo">330</span>     * server's data port to initiate a transfer.<a name="line.330"></a>
<span class="sourceLineNo">331</span>     */<a name="line.331"></a>
<span class="sourceLineNo">332</span>    public static final int PASSIVE_LOCAL_DATA_CONNECTION_MODE = 2;<a name="line.332"></a>
<span class="sourceLineNo">333</span>    /**<a name="line.333"></a>
<span class="sourceLineNo">334</span>     * A constant indicating the FTP session is expecting all transfers<a name="line.334"></a>
<span class="sourceLineNo">335</span>     * to occur between two remote servers and that the server<a name="line.335"></a>
<span class="sourceLineNo">336</span>     * the client is connected to is in passive mode, requiring the other<a name="line.336"></a>
<span class="sourceLineNo">337</span>     * server to connect to the first server's data port to initiate a data<a name="line.337"></a>
<span class="sourceLineNo">338</span>     * transfer.<a name="line.338"></a>
<span class="sourceLineNo">339</span>     */<a name="line.339"></a>
<span class="sourceLineNo">340</span>    public static final int PASSIVE_REMOTE_DATA_CONNECTION_MODE = 3;<a name="line.340"></a>
<span class="sourceLineNo">341</span><a name="line.341"></a>
<span class="sourceLineNo">342</span>    private int __dataConnectionMode;<a name="line.342"></a>
<span class="sourceLineNo">343</span>    private int __dataTimeout;<a name="line.343"></a>
<span class="sourceLineNo">344</span>    private int __passivePort;<a name="line.344"></a>
<span class="sourceLineNo">345</span>    private String __passiveHost;<a name="line.345"></a>
<span class="sourceLineNo">346</span>    private final Random __random;<a name="line.346"></a>
<span class="sourceLineNo">347</span>    private int __activeMinPort;<a name="line.347"></a>
<span class="sourceLineNo">348</span>    private int __activeMaxPort;<a name="line.348"></a>
<span class="sourceLineNo">349</span>    private InetAddress __activeExternalHost;<a name="line.349"></a>
<span class="sourceLineNo">350</span>    private InetAddress __reportActiveExternalHost; // overrides __activeExternalHost in EPRT/PORT commands<a name="line.350"></a>
<span class="sourceLineNo">351</span>    /** The address to bind to on passive connections, if necessary. */<a name="line.351"></a>
<span class="sourceLineNo">352</span>    private InetAddress __passiveLocalHost;<a name="line.352"></a>
<span class="sourceLineNo">353</span><a name="line.353"></a>
<span class="sourceLineNo">354</span>    private int __fileType;<a name="line.354"></a>
<span class="sourceLineNo">355</span>    @SuppressWarnings("unused") // fields are written, but currently not read<a name="line.355"></a>
<span class="sourceLineNo">356</span>    private int __fileFormat;<a name="line.356"></a>
<span class="sourceLineNo">357</span>    @SuppressWarnings("unused") // field is written, but currently not read<a name="line.357"></a>
<span class="sourceLineNo">358</span>    private int __fileStructure;<a name="line.358"></a>
<span class="sourceLineNo">359</span>    @SuppressWarnings("unused") // field is written, but currently not read<a name="line.359"></a>
<span class="sourceLineNo">360</span>    private int __fileTransferMode;<a name="line.360"></a>
<span class="sourceLineNo">361</span>    private boolean __remoteVerificationEnabled;<a name="line.361"></a>
<span class="sourceLineNo">362</span>    private long __restartOffset;<a name="line.362"></a>
<span class="sourceLineNo">363</span>    private FTPFileEntryParserFactory __parserFactory;<a name="line.363"></a>
<span class="sourceLineNo">364</span>    private int __bufferSize; // buffersize for buffered data streams<a name="line.364"></a>
<span class="sourceLineNo">365</span>    private int __sendDataSocketBufferSize;<a name="line.365"></a>
<span class="sourceLineNo">366</span>    private int __receiveDataSocketBufferSize;<a name="line.366"></a>
<span class="sourceLineNo">367</span>    private boolean __listHiddenFiles;<a name="line.367"></a>
<span class="sourceLineNo">368</span>    private boolean __useEPSVwithIPv4; // whether to attempt EPSV with an IPv4 connection<a name="line.368"></a>
<span class="sourceLineNo">369</span><a name="line.369"></a>
<span class="sourceLineNo">370</span>    // __systemName is a cached value that should not be referenced directly<a name="line.370"></a>
<span class="sourceLineNo">371</span>    // except when assigned in getSystemName and __initDefaults.<a name="line.371"></a>
<span class="sourceLineNo">372</span>    private String __systemName;<a name="line.372"></a>
<span class="sourceLineNo">373</span><a name="line.373"></a>
<span class="sourceLineNo">374</span>    // __entryParser is a cached value that should not be referenced directly<a name="line.374"></a>
<span class="sourceLineNo">375</span>    // except when assigned in listFiles(String, String) and __initDefaults.<a name="line.375"></a>
<span class="sourceLineNo">376</span>    private FTPFileEntryParser __entryParser;<a name="line.376"></a>
<span class="sourceLineNo">377</span><a name="line.377"></a>
<span class="sourceLineNo">378</span>    // Key used to create the parser; necessary to ensure that the parser type is not ignored<a name="line.378"></a>
<span class="sourceLineNo">379</span>    private String __entryParserKey;<a name="line.379"></a>
<span class="sourceLineNo">380</span><a name="line.380"></a>
<span class="sourceLineNo">381</span>    private FTPClientConfig __configuration;<a name="line.381"></a>
<span class="sourceLineNo">382</span><a name="line.382"></a>
<span class="sourceLineNo">383</span>    // Listener used by store/retrieve methods to handle keepalive<a name="line.383"></a>
<span class="sourceLineNo">384</span>    private CopyStreamListener __copyStreamListener;<a name="line.384"></a>
<span class="sourceLineNo">385</span><a name="line.385"></a>
<span class="sourceLineNo">386</span>    // How long to wait before sending another control keep-alive message<a name="line.386"></a>
<span class="sourceLineNo">387</span>    private long __controlKeepAliveTimeout;<a name="line.387"></a>
<span class="sourceLineNo">388</span><a name="line.388"></a>
<span class="sourceLineNo">389</span>    // How long to wait (ms) for keepalive message replies before continuing<a name="line.389"></a>
<span class="sourceLineNo">390</span>    // Most FTP servers don't seem to support concurrent control and data connection usage<a name="line.390"></a>
<span class="sourceLineNo">391</span>    private int __controlKeepAliveReplyTimeout=1000;<a name="line.391"></a>
<span class="sourceLineNo">392</span><a name="line.392"></a>
<span class="sourceLineNo">393</span>    /**<a name="line.393"></a>
<span class="sourceLineNo">394</span>     * Enable or disable replacement of internal IP in passive mode. Default enabled.<a name="line.394"></a>
<span class="sourceLineNo">395</span>     */<a name="line.395"></a>
<span class="sourceLineNo">396</span>    private boolean __passiveNatWorkaround = true;<a name="line.396"></a>
<span class="sourceLineNo">397</span><a name="line.397"></a>
<span class="sourceLineNo">398</span>    /** Pattern for PASV mode responses. Groups: (n,n,n,n),(n),(n) */<a name="line.398"></a>
<span class="sourceLineNo">399</span>    private static final java.util.regex.Pattern __PARMS_PAT;<a name="line.399"></a>
<span class="sourceLineNo">400</span>    static {<a name="line.400"></a>
<span class="sourceLineNo">401</span>        __PARMS_PAT = java.util.regex.Pattern.compile(<a name="line.401"></a>
<span class="sourceLineNo">402</span>                "(\\d{1,3},\\d{1,3},\\d{1,3},\\d{1,3}),(\\d{1,3}),(\\d{1,3})");<a name="line.402"></a>
<span class="sourceLineNo">403</span>    }<a name="line.403"></a>
<span class="sourceLineNo">404</span><a name="line.404"></a>
<span class="sourceLineNo">405</span>    /** Controls the automatic server encoding detection (only UTF-8 supported). */<a name="line.405"></a>
<span class="sourceLineNo">406</span>    private boolean __autodetectEncoding = false;<a name="line.406"></a>
<span class="sourceLineNo">407</span><a name="line.407"></a>
<span class="sourceLineNo">408</span>    /** Map of FEAT responses. If null, has not been initialised. */<a name="line.408"></a>
<span class="sourceLineNo">409</span>    private HashMap&lt;String, Set&lt;String&gt;&gt; __featuresMap;<a name="line.409"></a>
<span class="sourceLineNo">410</span><a name="line.410"></a>
<span class="sourceLineNo">411</span>    private static class PropertiesSingleton {<a name="line.411"></a>
<span class="sourceLineNo">412</span><a name="line.412"></a>
<span class="sourceLineNo">413</span>        static final Properties PROPERTIES;<a name="line.413"></a>
<span class="sourceLineNo">414</span><a name="line.414"></a>
<span class="sourceLineNo">415</span>        static {<a name="line.415"></a>
<span class="sourceLineNo">416</span>            InputStream resourceAsStream = FTPClient.class.getResourceAsStream(SYSTEM_TYPE_PROPERTIES);<a name="line.416"></a>
<span class="sourceLineNo">417</span>            Properties p = null;<a name="line.417"></a>
<span class="sourceLineNo">418</span>            if (resourceAsStream != null) {<a name="line.418"></a>
<span class="sourceLineNo">419</span>                p = new Properties();<a name="line.419"></a>
<span class="sourceLineNo">420</span>                try {<a name="line.420"></a>
<span class="sourceLineNo">421</span>                    p.load(resourceAsStream);<a name="line.421"></a>
<span class="sourceLineNo">422</span>                } catch (IOException e) {<a name="line.422"></a>
<span class="sourceLineNo">423</span>                } finally {<a name="line.423"></a>
<span class="sourceLineNo">424</span>                    try {<a name="line.424"></a>
<span class="sourceLineNo">425</span>                        resourceAsStream.close();<a name="line.425"></a>
<span class="sourceLineNo">426</span>                    } catch (IOException e) {<a name="line.426"></a>
<span class="sourceLineNo">427</span>                        // Ignored<a name="line.427"></a>
<span class="sourceLineNo">428</span>                    }<a name="line.428"></a>
<span class="sourceLineNo">429</span>                }<a name="line.429"></a>
<span class="sourceLineNo">430</span>            }<a name="line.430"></a>
<span class="sourceLineNo">431</span>            PROPERTIES = p;<a name="line.431"></a>
<span class="sourceLineNo">432</span>        }<a name="line.432"></a>
<span class="sourceLineNo">433</span><a name="line.433"></a>
<span class="sourceLineNo">434</span>    }<a name="line.434"></a>
<span class="sourceLineNo">435</span>    private static Properties getOverrideProperties(){<a name="line.435"></a>
<span class="sourceLineNo">436</span>        return PropertiesSingleton.PROPERTIES;<a name="line.436"></a>
<span class="sourceLineNo">437</span>    }<a name="line.437"></a>
<span class="sourceLineNo">438</span><a name="line.438"></a>
<span class="sourceLineNo">439</span>    /**<a name="line.439"></a>
<span class="sourceLineNo">440</span>     * Default FTPClient constructor.  Creates a new FTPClient instance<a name="line.440"></a>
<span class="sourceLineNo">441</span>     * with the data connection mode set to<a name="line.441"></a>
<span class="sourceLineNo">442</span>     * &lt;code&gt; ACTIVE_LOCAL_DATA_CONNECTION_MODE &lt;/code&gt;, the file type<a name="line.442"></a>
<span class="sourceLineNo">443</span>     * set to &lt;code&gt; FTP.ASCII_FILE_TYPE &lt;/code&gt;, the<a name="line.443"></a>
<span class="sourceLineNo">444</span>     * file format set to &lt;code&gt; FTP.NON_PRINT_TEXT_FORMAT &lt;/code&gt;,<a name="line.444"></a>
<span class="sourceLineNo">445</span>     * the file structure set to &lt;code&gt; FTP.FILE_STRUCTURE &lt;/code&gt;, and<a name="line.445"></a>
<span class="sourceLineNo">446</span>     * the transfer mode set to &lt;code&gt; FTP.STREAM_TRANSFER_MODE &lt;/code&gt;.<a name="line.446"></a>
<span class="sourceLineNo">447</span>     * &lt;p&gt;<a name="line.447"></a>
<span class="sourceLineNo">448</span>     * The list parsing auto-detect feature can be configured to use lenient future<a name="line.448"></a>
<span class="sourceLineNo">449</span>     * dates (short dates may be up to one day in the future) as follows:<a name="line.449"></a>
<span class="sourceLineNo">450</span>     * &lt;pre&gt;<a name="line.450"></a>
<span class="sourceLineNo">451</span>     * FTPClient ftp = new FTPClient();<a name="line.451"></a>
<span class="sourceLineNo">452</span>     * FTPClientConfig config = new FTPClientConfig();<a name="line.452"></a>
<span class="sourceLineNo">453</span>     * config.setLenientFutureDates(true);<a name="line.453"></a>
<span class="sourceLineNo">454</span>     * ftp.configure(config );<a name="line.454"></a>
<span class="sourceLineNo">455</span>     * &lt;/pre&gt;<a name="line.455"></a>
<span class="sourceLineNo">456</span>     */<a name="line.456"></a>
<span class="sourceLineNo">457</span>    public FTPClient()<a name="line.457"></a>
<span class="sourceLineNo">458</span>    {<a name="line.458"></a>
<span class="sourceLineNo">459</span>        __initDefaults();<a name="line.459"></a>
<span class="sourceLineNo">460</span>        __dataTimeout = -1;<a name="line.460"></a>
<span class="sourceLineNo">461</span>        __remoteVerificationEnabled = true;<a name="line.461"></a>
<span class="sourceLineNo">462</span>        __parserFactory = new DefaultFTPFileEntryParserFactory();<a name="line.462"></a>
<span class="sourceLineNo">463</span>        __configuration      = null;<a name="line.463"></a>
<span class="sourceLineNo">464</span>        __listHiddenFiles = false;<a name="line.464"></a>
<span class="sourceLineNo">465</span>        __useEPSVwithIPv4 = false;<a name="line.465"></a>
<span class="sourceLineNo">466</span>        __random = new Random();<a name="line.466"></a>
<span class="sourceLineNo">467</span>        __passiveLocalHost   = null;<a name="line.467"></a>
<span class="sourceLineNo">468</span>    }<a name="line.468"></a>
<span class="sourceLineNo">469</span><a name="line.469"></a>
<span class="sourceLineNo">470</span><a name="line.470"></a>
<span class="sourceLineNo">471</span>    private void __initDefaults()<a name="line.471"></a>
<span class="sourceLineNo">472</span>    {<a name="line.472"></a>
<span class="sourceLineNo">473</span>        __dataConnectionMode = ACTIVE_LOCAL_DATA_CONNECTION_MODE;<a name="line.473"></a>
<span class="sourceLineNo">474</span>        __passiveHost        = null;<a name="line.474"></a>
<span class="sourceLineNo">475</span>        __passivePort        = -1;<a name="line.475"></a>
<span class="sourceLineNo">476</span>        __activeExternalHost = null;<a name="line.476"></a>
<span class="sourceLineNo">477</span>        __reportActiveExternalHost = null;<a name="line.477"></a>
<span class="sourceLineNo">478</span>        __activeMinPort = 0;<a name="line.478"></a>
<span class="sourceLineNo">479</span>        __activeMaxPort = 0;<a name="line.479"></a>
<span class="sourceLineNo">480</span>        __fileType           = FTP.ASCII_FILE_TYPE;<a name="line.480"></a>
<span class="sourceLineNo">481</span>        __fileStructure      = FTP.FILE_STRUCTURE;<a name="line.481"></a>
<span class="sourceLineNo">482</span>        __fileFormat         = FTP.NON_PRINT_TEXT_FORMAT;<a name="line.482"></a>
<span class="sourceLineNo">483</span>        __fileTransferMode   = FTP.STREAM_TRANSFER_MODE;<a name="line.483"></a>
<span class="sourceLineNo">484</span>        __restartOffset      = 0;<a name="line.484"></a>
<span class="sourceLineNo">485</span>        __systemName         = null;<a name="line.485"></a>
<span class="sourceLineNo">486</span>        __entryParser        = null;<a name="line.486"></a>
<span class="sourceLineNo">487</span>        __entryParserKey    = "";<a name="line.487"></a>
<span class="sourceLineNo">488</span>        __featuresMap = null;<a name="line.488"></a>
<span class="sourceLineNo">489</span>    }<a name="line.489"></a>
<span class="sourceLineNo">490</span><a name="line.490"></a>
<span class="sourceLineNo">491</span>    /**<a name="line.491"></a>
<span class="sourceLineNo">492</span>     * Parse the pathname from a CWD reply.<a name="line.492"></a>
<span class="sourceLineNo">493</span>     * &lt;p&gt;<a name="line.493"></a>
<span class="sourceLineNo">494</span>     * According to RFC959 (http://www.ietf.org/rfc/rfc959.txt),<a name="line.494"></a>
<span class="sourceLineNo">495</span>     * it should be the same as for MKD i.e.<a name="line.495"></a>
<span class="sourceLineNo">496</span>     * {@code 257&lt;space&gt;"&lt;directory-name&gt;"[&lt;space&gt;commentary]}<a name="line.496"></a>
<span class="sourceLineNo">497</span>     * where any double-quotes in {@code &lt;directory-name&gt;} are doubled.<a name="line.497"></a>
<span class="sourceLineNo">498</span>     * Unlike MKD, the commentary is optional.<a name="line.498"></a>
<span class="sourceLineNo">499</span>     * &lt;p&gt;<a name="line.499"></a>
<span class="sourceLineNo">500</span>     * However, see NET-442 for an exception.<a name="line.500"></a>
<span class="sourceLineNo">501</span>     *<a name="line.501"></a>
<span class="sourceLineNo">502</span>     * @param reply<a name="line.502"></a>
<span class="sourceLineNo">503</span>     * @return the pathname, without enclosing quotes,<a name="line.503"></a>
<span class="sourceLineNo">504</span>     * or the full string after the reply code and space if the syntax is invalid<a name="line.504"></a>
<span class="sourceLineNo">505</span>     * (i.e. enclosing quotes are missing or embedded quotes are not doubled)<a name="line.505"></a>
<span class="sourceLineNo">506</span>     */<a name="line.506"></a>
<span class="sourceLineNo">507</span>    // package protected for access by test cases<a name="line.507"></a>
<span class="sourceLineNo">508</span>    static String __parsePathname(String reply)<a name="line.508"></a>
<span class="sourceLineNo">509</span>    {<a name="line.509"></a>
<span class="sourceLineNo">510</span>        String param = reply.substring(REPLY_CODE_LEN + 1);<a name="line.510"></a>
<span class="sourceLineNo">511</span>        if (param.startsWith("\"")) {<a name="line.511"></a>
<span class="sourceLineNo">512</span>            StringBuilder sb = new StringBuilder();<a name="line.512"></a>
<span class="sourceLineNo">513</span>            boolean quoteSeen = false;<a name="line.513"></a>
<span class="sourceLineNo">514</span>            // start after initial quote<a name="line.514"></a>
<span class="sourceLineNo">515</span>            for(int i=1; i &lt; param.length(); i++) {<a name="line.515"></a>
<span class="sourceLineNo">516</span>                char ch = param.charAt(i);<a name="line.516"></a>
<span class="sourceLineNo">517</span>                if (ch=='"') {<a name="line.517"></a>
<span class="sourceLineNo">518</span>                    if (quoteSeen) {<a name="line.518"></a>
<span class="sourceLineNo">519</span>                        sb.append(ch);<a name="line.519"></a>
<span class="sourceLineNo">520</span>                        quoteSeen=false;<a name="line.520"></a>
<span class="sourceLineNo">521</span>                    } else {<a name="line.521"></a>
<span class="sourceLineNo">522</span>                        // don't output yet, in case doubled<a name="line.522"></a>
<span class="sourceLineNo">523</span>                        quoteSeen=true;<a name="line.523"></a>
<span class="sourceLineNo">524</span>                    }<a name="line.524"></a>
<span class="sourceLineNo">525</span>                } else {<a name="line.525"></a>
<span class="sourceLineNo">526</span>                    if (quoteSeen) { // found lone trailing quote within string<a name="line.526"></a>
<span class="sourceLineNo">527</span>                        return sb.toString();<a name="line.527"></a>
<span class="sourceLineNo">528</span>                    }<a name="line.528"></a>
<span class="sourceLineNo">529</span>                    sb.append(ch); // just another character<a name="line.529"></a>
<span class="sourceLineNo">530</span>                }<a name="line.530"></a>
<span class="sourceLineNo">531</span>            }<a name="line.531"></a>
<span class="sourceLineNo">532</span>            if (quoteSeen) { // found lone trailing quote at end of string<a name="line.532"></a>
<span class="sourceLineNo">533</span>                return sb.toString();<a name="line.533"></a>
<span class="sourceLineNo">534</span>            }<a name="line.534"></a>
<span class="sourceLineNo">535</span>        }<a name="line.535"></a>
<span class="sourceLineNo">536</span>        // malformed reply, return all after reply code and space<a name="line.536"></a>
<span class="sourceLineNo">537</span>        return param;<a name="line.537"></a>
<span class="sourceLineNo">538</span>    }<a name="line.538"></a>
<span class="sourceLineNo">539</span><a name="line.539"></a>
<span class="sourceLineNo">540</span>    /**<a name="line.540"></a>
<span class="sourceLineNo">541</span>     * @since 3.1<a name="line.541"></a>
<span class="sourceLineNo">542</span>     */<a name="line.542"></a>
<span class="sourceLineNo">543</span>    protected void _parsePassiveModeReply(String reply)<a name="line.543"></a>
<span class="sourceLineNo">544</span>    throws MalformedServerReplyException<a name="line.544"></a>
<span class="sourceLineNo">545</span>    {<a name="line.545"></a>
<span class="sourceLineNo">546</span>        java.util.regex.Matcher m = __PARMS_PAT.matcher(reply);<a name="line.546"></a>
<span class="sourceLineNo">547</span>        if (!m.find()) {<a name="line.547"></a>
<span class="sourceLineNo">548</span>            throw new MalformedServerReplyException(<a name="line.548"></a>
<span class="sourceLineNo">549</span>                    "Could not parse passive host information.\nServer Reply: " + reply);<a name="line.549"></a>
<span class="sourceLineNo">550</span>        }<a name="line.550"></a>
<span class="sourceLineNo">551</span><a name="line.551"></a>
<span class="sourceLineNo">552</span>        __passiveHost = m.group(1).replace(',', '.'); // Fix up to look like IP address<a name="line.552"></a>
<span class="sourceLineNo">553</span><a name="line.553"></a>
<span class="sourceLineNo">554</span>        try<a name="line.554"></a>
<span class="sourceLineNo">555</span>        {<a name="line.555"></a>
<span class="sourceLineNo">556</span>            int oct1 = Integer.parseInt(m.group(2));<a name="line.556"></a>
<span class="sourceLineNo">557</span>            int oct2 = Integer.parseInt(m.group(3));<a name="line.557"></a>
<span class="sourceLineNo">558</span>            __passivePort = (oct1 &lt;&lt; 8) | oct2;<a name="line.558"></a>
<span class="sourceLineNo">559</span>        }<a name="line.559"></a>
<span class="sourceLineNo">560</span>        catch (NumberFormatException e)<a name="line.560"></a>
<span class="sourceLineNo">561</span>        {<a name="line.561"></a>
<span class="sourceLineNo">562</span>            throw new MalformedServerReplyException(<a name="line.562"></a>
<span class="sourceLineNo">563</span>                    "Could not parse passive port information.\nServer Reply: " + reply);<a name="line.563"></a>
<span class="sourceLineNo">564</span>        }<a name="line.564"></a>
<span class="sourceLineNo">565</span><a name="line.565"></a>
<span class="sourceLineNo">566</span>        if (__passiveNatWorkaround) {<a name="line.566"></a>
<span class="sourceLineNo">567</span>            try {<a name="line.567"></a>
<span class="sourceLineNo">568</span>                InetAddress host = InetAddress.getByName(__passiveHost);<a name="line.568"></a>
<span class="sourceLineNo">569</span>                // reply is a local address, but target is not - assume NAT box changed the PASV reply<a name="line.569"></a>
<span class="sourceLineNo">570</span>                if (host.isSiteLocalAddress()) {<a name="line.570"></a>
<span class="sourceLineNo">571</span>                    InetAddress remote = getRemoteAddress();<a name="line.571"></a>
<span class="sourceLineNo">572</span>                    if (!remote.isSiteLocalAddress()){<a name="line.572"></a>
<span class="sourceLineNo">573</span>                        String hostAddress = remote.getHostAddress();<a name="line.573"></a>
<span class="sourceLineNo">574</span>                        fireReplyReceived(0,<a name="line.574"></a>
<span class="sourceLineNo">575</span>                                    "[Replacing site local address "+__passiveHost+" with "+hostAddress+"]\n");<a name="line.575"></a>
<span class="sourceLineNo">576</span>                        __passiveHost = hostAddress;<a name="line.576"></a>
<span class="sourceLineNo">577</span>                    }<a name="line.577"></a>
<span class="sourceLineNo">578</span>                }<a name="line.578"></a>
<span class="sourceLineNo">579</span>            } catch (UnknownHostException e) { // Should not happen as we are passing in an IP address<a name="line.579"></a>
<span class="sourceLineNo">580</span>                throw new MalformedServerReplyException(<a name="line.580"></a>
<span class="sourceLineNo">581</span>                        "Could not parse passive host information.\nServer Reply: " + reply);<a name="line.581"></a>
<span class="sourceLineNo">582</span>            }<a name="line.582"></a>
<span class="sourceLineNo">583</span>        }<a name="line.583"></a>
<span class="sourceLineNo">584</span>    }<a name="line.584"></a>
<span class="sourceLineNo">585</span><a name="line.585"></a>
<span class="sourceLineNo">586</span>    protected void _parseExtendedPassiveModeReply(String reply)<a name="line.586"></a>
<span class="sourceLineNo">587</span>    throws MalformedServerReplyException<a name="line.587"></a>
<span class="sourceLineNo">588</span>    {<a name="line.588"></a>
<span class="sourceLineNo">589</span>        reply = reply.substring(reply.indexOf('(') + 1,<a name="line.589"></a>
<span class="sourceLineNo">590</span>                reply.indexOf(')')).trim();<a name="line.590"></a>
<span class="sourceLineNo">591</span><a name="line.591"></a>
<span class="sourceLineNo">592</span>        char delim1, delim2, delim3, delim4;<a name="line.592"></a>
<span class="sourceLineNo">593</span>        delim1 = reply.charAt(0);<a name="line.593"></a>
<span class="sourceLineNo">594</span>        delim2 = reply.charAt(1);<a name="line.594"></a>
<span class="sourceLineNo">595</span>        delim3 = reply.charAt(2);<a name="line.595"></a>
<span class="sourceLineNo">596</span>        delim4 = reply.charAt(reply.length()-1);<a name="line.596"></a>
<span class="sourceLineNo">597</span><a name="line.597"></a>
<span class="sourceLineNo">598</span>        if (!(delim1 == delim2) || !(delim2 == delim3)<a name="line.598"></a>
<span class="sourceLineNo">599</span>                || !(delim3 == delim4)) {<a name="line.599"></a>
<span class="sourceLineNo">600</span>            throw new MalformedServerReplyException(<a name="line.600"></a>
<span class="sourceLineNo">601</span>                    "Could not parse extended passive host information.\nServer Reply: " + reply);<a name="line.601"></a>
<span class="sourceLineNo">602</span>        }<a name="line.602"></a>
<span class="sourceLineNo">603</span><a name="line.603"></a>
<span class="sourceLineNo">604</span>        int port;<a name="line.604"></a>
<span class="sourceLineNo">605</span>        try<a name="line.605"></a>
<span class="sourceLineNo">606</span>        {<a name="line.606"></a>
<span class="sourceLineNo">607</span>            port = Integer.parseInt(reply.substring(3, reply.length()-1));<a name="line.607"></a>
<span class="sourceLineNo">608</span>        }<a name="line.608"></a>
<span class="sourceLineNo">609</span>        catch (NumberFormatException e)<a name="line.609"></a>
<span class="sourceLineNo">610</span>        {<a name="line.610"></a>
<span class="sourceLineNo">611</span>            throw new MalformedServerReplyException(<a name="line.611"></a>
<span class="sourceLineNo">612</span>                    "Could not parse extended passive host information.\nServer Reply: " + reply);<a name="line.612"></a>
<span class="sourceLineNo">613</span>        }<a name="line.613"></a>
<span class="sourceLineNo">614</span><a name="line.614"></a>
<span class="sourceLineNo">615</span><a name="line.615"></a>
<span class="sourceLineNo">616</span>        // in EPSV mode, the passive host address is implicit<a name="line.616"></a>
<span class="sourceLineNo">617</span>        __passiveHost = getRemoteAddress().getHostAddress();<a name="line.617"></a>
<span class="sourceLineNo">618</span>        __passivePort = port;<a name="line.618"></a>
<span class="sourceLineNo">619</span>    }<a name="line.619"></a>
<span class="sourceLineNo">620</span><a name="line.620"></a>
<span class="sourceLineNo">621</span>    private boolean __storeFile(FTPCmd command, String remote, InputStream local)<a name="line.621"></a>
<span class="sourceLineNo">622</span>    throws IOException<a name="line.622"></a>
<span class="sourceLineNo">623</span>    {<a name="line.623"></a>
<span class="sourceLineNo">624</span>        return _storeFile(command.getCommand(), remote, local);<a name="line.624"></a>
<span class="sourceLineNo">625</span>    }<a name="line.625"></a>
<span class="sourceLineNo">626</span><a name="line.626"></a>
<span class="sourceLineNo">627</span>    /**<a name="line.627"></a>
<span class="sourceLineNo">628</span>     * @since 3.1<a name="line.628"></a>
<span class="sourceLineNo">629</span>     */<a name="line.629"></a>
<span class="sourceLineNo">630</span>    protected boolean _storeFile(String command, String remote, InputStream local)<a name="line.630"></a>
<span class="sourceLineNo">631</span>    throws IOException<a name="line.631"></a>
<span class="sourceLineNo">632</span>    {<a name="line.632"></a>
<span class="sourceLineNo">633</span>        Socket socket = _openDataConnection_(command, remote);<a name="line.633"></a>
<span class="sourceLineNo">634</span><a name="line.634"></a>
<span class="sourceLineNo">635</span>        if (socket == null) {<a name="line.635"></a>
<span class="sourceLineNo">636</span>            return false;<a name="line.636"></a>
<span class="sourceLineNo">637</span>        }<a name="line.637"></a>
<span class="sourceLineNo">638</span><a name="line.638"></a>
<span class="sourceLineNo">639</span>        OutputStream output = getBufferedOutputStream(socket.getOutputStream());<a name="line.639"></a>
<span class="sourceLineNo">640</span><a name="line.640"></a>
<span class="sourceLineNo">641</span>        if (__fileType == ASCII_FILE_TYPE) {<a name="line.641"></a>
<span class="sourceLineNo">642</span>            output = new ToNetASCIIOutputStream(output);<a name="line.642"></a>
<span class="sourceLineNo">643</span>        }<a name="line.643"></a>
<span class="sourceLineNo">644</span><a name="line.644"></a>
<span class="sourceLineNo">645</span>        CSL csl = null;<a name="line.645"></a>
<span class="sourceLineNo">646</span>        if (__controlKeepAliveTimeout &gt; 0) {<a name="line.646"></a>
<span class="sourceLineNo">647</span>            csl = new CSL(this, __controlKeepAliveTimeout, __controlKeepAliveReplyTimeout);<a name="line.647"></a>
<span class="sourceLineNo">648</span>        }<a name="line.648"></a>
<span class="sourceLineNo">649</span><a name="line.649"></a>
<span class="sourceLineNo">650</span>        // Treat everything else as binary for now<a name="line.650"></a>
<span class="sourceLineNo">651</span>        try<a name="line.651"></a>
<span class="sourceLineNo">652</span>        {<a name="line.652"></a>
<span class="sourceLineNo">653</span>            Util.copyStream(local, output, getBufferSize(),<a name="line.653"></a>
<span class="sourceLineNo">654</span>                    CopyStreamEvent.UNKNOWN_STREAM_SIZE, __mergeListeners(csl),<a name="line.654"></a>
<span class="sourceLineNo">655</span>                    false);<a name="line.655"></a>
<span class="sourceLineNo">656</span>        }<a name="line.656"></a>
<span class="sourceLineNo">657</span>        catch (IOException e)<a name="line.657"></a>
<span class="sourceLineNo">658</span>        {<a name="line.658"></a>
<span class="sourceLineNo">659</span>            Util.closeQuietly(socket); // ignore close errors here<a name="line.659"></a>
<span class="sourceLineNo">660</span>            if (csl != null) {<a name="line.660"></a>
<span class="sourceLineNo">661</span>                csl.cleanUp(); // fetch any outstanding keepalive replies<a name="line.661"></a>
<span class="sourceLineNo">662</span>            }<a name="line.662"></a>
<span class="sourceLineNo">663</span>            throw e;<a name="line.663"></a>
<span class="sourceLineNo">664</span>        }<a name="line.664"></a>
<span class="sourceLineNo">665</span><a name="line.665"></a>
<span class="sourceLineNo">666</span>        output.close(); // ensure the file is fully written<a name="line.666"></a>
<span class="sourceLineNo">667</span>        socket.close(); // done writing the file<a name="line.667"></a>
<span class="sourceLineNo">668</span>        if (csl != null) {<a name="line.668"></a>
<span class="sourceLineNo">669</span>            csl.cleanUp(); // fetch any outstanding keepalive replies<a name="line.669"></a>
<span class="sourceLineNo">670</span>        }<a name="line.670"></a>
<span class="sourceLineNo">671</span>        // Get the transfer response<a name="line.671"></a>
<span class="sourceLineNo">672</span>        boolean ok = completePendingCommand();<a name="line.672"></a>
<span class="sourceLineNo">673</span>        return ok;<a name="line.673"></a>
<span class="sourceLineNo">674</span>    }<a name="line.674"></a>
<span class="sourceLineNo">675</span><a name="line.675"></a>
<span class="sourceLineNo">676</span>    private OutputStream __storeFileStream(FTPCmd command, String remote)<a name="line.676"></a>
<span class="sourceLineNo">677</span>    throws IOException<a name="line.677"></a>
<span class="sourceLineNo">678</span>    {<a name="line.678"></a>
<span class="sourceLineNo">679</span>        return _storeFileStream(command.getCommand(), remote);<a name="line.679"></a>
<span class="sourceLineNo">680</span>    }<a name="line.680"></a>
<span class="sourceLineNo">681</span><a name="line.681"></a>
<span class="sourceLineNo">682</span>    /**<a name="line.682"></a>
<span class="sourceLineNo">683</span>     * @since 3.1<a name="line.683"></a>
<span class="sourceLineNo">684</span>     */<a name="line.684"></a>
<span class="sourceLineNo">685</span>    protected OutputStream _storeFileStream(String command, String remote)<a name="line.685"></a>
<span class="sourceLineNo">686</span>    throws IOException<a name="line.686"></a>
<span class="sourceLineNo">687</span>    {<a name="line.687"></a>
<span class="sourceLineNo">688</span>        Socket socket = _openDataConnection_(command, remote);<a name="line.688"></a>
<span class="sourceLineNo">689</span><a name="line.689"></a>
<span class="sourceLineNo">690</span>        if (socket == null) {<a name="line.690"></a>
<span class="sourceLineNo">691</span>            return null;<a name="line.691"></a>
<span class="sourceLineNo">692</span>        }<a name="line.692"></a>
<span class="sourceLineNo">693</span><a name="line.693"></a>
<span class="sourceLineNo">694</span>        OutputStream output = socket.getOutputStream();<a name="line.694"></a>
<span class="sourceLineNo">695</span>        if (__fileType == ASCII_FILE_TYPE) {<a name="line.695"></a>
<span class="sourceLineNo">696</span>            // We buffer ascii transfers because the buffering has to<a name="line.696"></a>
<span class="sourceLineNo">697</span>            // be interposed between ToNetASCIIOutputSream and the underlying<a name="line.697"></a>
<span class="sourceLineNo">698</span>            // socket output stream.  We don't buffer binary transfers<a name="line.698"></a>
<span class="sourceLineNo">699</span>            // because we don't want to impose a buffering policy on the<a name="line.699"></a>
<span class="sourceLineNo">700</span>            // programmer if possible.  Programmers can decide on their<a name="line.700"></a>
<span class="sourceLineNo">701</span>            // own if they want to wrap the SocketOutputStream we return<a name="line.701"></a>
<span class="sourceLineNo">702</span>            // for file types other than ASCII.<a name="line.702"></a>
<span class="sourceLineNo">703</span>            output = getBufferedOutputStream(output);<a name="line.703"></a>
<span class="sourceLineNo">704</span>            output = new ToNetASCIIOutputStream(output);<a name="line.704"></a>
<span class="sourceLineNo">705</span><a name="line.705"></a>
<span class="sourceLineNo">706</span>        }<a name="line.706"></a>
<span class="sourceLineNo">707</span>        return new org.apache.commons.net.io.SocketOutputStream(socket, output);<a name="line.707"></a>
<span class="sourceLineNo">708</span>    }<a name="line.708"></a>
<span class="sourceLineNo">709</span><a name="line.709"></a>
<span class="sourceLineNo">710</span><a name="line.710"></a>
<span class="sourceLineNo">711</span>    /**<a name="line.711"></a>
<span class="sourceLineNo">712</span>     * Establishes a data connection with the FTP server, returning<a name="line.712"></a>
<span class="sourceLineNo">713</span>     * a Socket for the connection if successful.  If a restart<a name="line.713"></a>
<span class="sourceLineNo">714</span>     * offset has been set with {@link #setRestartOffset(long)},<a name="line.714"></a>
<span class="sourceLineNo">715</span>     * a REST command is issued to the server with the offset as<a name="line.715"></a>
<span class="sourceLineNo">716</span>     * an argument before establishing the data connection.  Active<a name="line.716"></a>
<span class="sourceLineNo">717</span>     * mode connections also cause a local PORT command to be issued.<a name="line.717"></a>
<span class="sourceLineNo">718</span>     * &lt;p&gt;<a name="line.718"></a>
<span class="sourceLineNo">719</span>     * @param command  The int representation of the FTP command to send.<a name="line.719"></a>
<span class="sourceLineNo">720</span>     * @param arg The arguments to the FTP command.  If this parameter is<a name="line.720"></a>
<span class="sourceLineNo">721</span>     *             set to null, then the command is sent with no argument.<a name="line.721"></a>
<span class="sourceLineNo">722</span>     * @return A Socket corresponding to the established data connection.<a name="line.722"></a>
<span class="sourceLineNo">723</span>     *         Null is returned if an FTP protocol error is reported at<a name="line.723"></a>
<span class="sourceLineNo">724</span>     *         any point during the establishment and initialization of<a name="line.724"></a>
<span class="sourceLineNo">725</span>     *         the connection.<a name="line.725"></a>
<span class="sourceLineNo">726</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.726"></a>
<span class="sourceLineNo">727</span>     *      command to the server or receiving a reply from the server.<a name="line.727"></a>
<span class="sourceLineNo">728</span>     * @deprecated (3.3) Use {@link #_openDataConnection_(FTPCmd, String)} instead<a name="line.728"></a>
<span class="sourceLineNo">729</span>     */<a name="line.729"></a>
<span class="sourceLineNo">730</span>    @Deprecated<a name="line.730"></a>
<span class="sourceLineNo">731</span>    protected Socket _openDataConnection_(int command, String arg)<a name="line.731"></a>
<span class="sourceLineNo">732</span>    throws IOException<a name="line.732"></a>
<span class="sourceLineNo">733</span>    {<a name="line.733"></a>
<span class="sourceLineNo">734</span>        return _openDataConnection_(FTPCommand.getCommand(command), arg);<a name="line.734"></a>
<span class="sourceLineNo">735</span>    }<a name="line.735"></a>
<span class="sourceLineNo">736</span><a name="line.736"></a>
<span class="sourceLineNo">737</span>    /**<a name="line.737"></a>
<span class="sourceLineNo">738</span>     * Establishes a data connection with the FTP server, returning<a name="line.738"></a>
<span class="sourceLineNo">739</span>     * a Socket for the connection if successful.  If a restart<a name="line.739"></a>
<span class="sourceLineNo">740</span>     * offset has been set with {@link #setRestartOffset(long)},<a name="line.740"></a>
<span class="sourceLineNo">741</span>     * a REST command is issued to the server with the offset as<a name="line.741"></a>
<span class="sourceLineNo">742</span>     * an argument before establishing the data connection.  Active<a name="line.742"></a>
<span class="sourceLineNo">743</span>     * mode connections also cause a local PORT command to be issued.<a name="line.743"></a>
<span class="sourceLineNo">744</span>     * &lt;p&gt;<a name="line.744"></a>
<span class="sourceLineNo">745</span>     * @param command  The int representation of the FTP command to send.<a name="line.745"></a>
<span class="sourceLineNo">746</span>     * @param arg The arguments to the FTP command.  If this parameter is<a name="line.746"></a>
<span class="sourceLineNo">747</span>     *             set to null, then the command is sent with no argument.<a name="line.747"></a>
<span class="sourceLineNo">748</span>     * @return A Socket corresponding to the established data connection.<a name="line.748"></a>
<span class="sourceLineNo">749</span>     *         Null is returned if an FTP protocol error is reported at<a name="line.749"></a>
<span class="sourceLineNo">750</span>     *         any point during the establishment and initialization of<a name="line.750"></a>
<span class="sourceLineNo">751</span>     *         the connection.<a name="line.751"></a>
<span class="sourceLineNo">752</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.752"></a>
<span class="sourceLineNo">753</span>     *      command to the server or receiving a reply from the server.<a name="line.753"></a>
<span class="sourceLineNo">754</span>     * @since 3.3<a name="line.754"></a>
<span class="sourceLineNo">755</span>     */<a name="line.755"></a>
<span class="sourceLineNo">756</span>    protected Socket _openDataConnection_(FTPCmd command, String arg)<a name="line.756"></a>
<span class="sourceLineNo">757</span>    throws IOException<a name="line.757"></a>
<span class="sourceLineNo">758</span>    {<a name="line.758"></a>
<span class="sourceLineNo">759</span>        return _openDataConnection_(command.getCommand(), arg);<a name="line.759"></a>
<span class="sourceLineNo">760</span>    }<a name="line.760"></a>
<span class="sourceLineNo">761</span><a name="line.761"></a>
<span class="sourceLineNo">762</span>    /**<a name="line.762"></a>
<span class="sourceLineNo">763</span>     * Establishes a data connection with the FTP server, returning<a name="line.763"></a>
<span class="sourceLineNo">764</span>     * a Socket for the connection if successful.  If a restart<a name="line.764"></a>
<span class="sourceLineNo">765</span>     * offset has been set with {@link #setRestartOffset(long)},<a name="line.765"></a>
<span class="sourceLineNo">766</span>     * a REST command is issued to the server with the offset as<a name="line.766"></a>
<span class="sourceLineNo">767</span>     * an argument before establishing the data connection.  Active<a name="line.767"></a>
<span class="sourceLineNo">768</span>     * mode connections also cause a local PORT command to be issued.<a name="line.768"></a>
<span class="sourceLineNo">769</span>     * &lt;p&gt;<a name="line.769"></a>
<span class="sourceLineNo">770</span>     * @param command  The text representation of the FTP command to send.<a name="line.770"></a>
<span class="sourceLineNo">771</span>     * @param arg The arguments to the FTP command.  If this parameter is<a name="line.771"></a>
<span class="sourceLineNo">772</span>     *             set to null, then the command is sent with no argument.<a name="line.772"></a>
<span class="sourceLineNo">773</span>     * @return A Socket corresponding to the established data connection.<a name="line.773"></a>
<span class="sourceLineNo">774</span>     *         Null is returned if an FTP protocol error is reported at<a name="line.774"></a>
<span class="sourceLineNo">775</span>     *         any point during the establishment and initialization of<a name="line.775"></a>
<span class="sourceLineNo">776</span>     *         the connection.<a name="line.776"></a>
<span class="sourceLineNo">777</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.777"></a>
<span class="sourceLineNo">778</span>     *      command to the server or receiving a reply from the server.<a name="line.778"></a>
<span class="sourceLineNo">779</span>     * @since 3.1<a name="line.779"></a>
<span class="sourceLineNo">780</span>     */<a name="line.780"></a>
<span class="sourceLineNo">781</span>    protected Socket _openDataConnection_(String command, String arg)<a name="line.781"></a>
<span class="sourceLineNo">782</span>    throws IOException<a name="line.782"></a>
<span class="sourceLineNo">783</span>    {<a name="line.783"></a>
<span class="sourceLineNo">784</span>        if (__dataConnectionMode != ACTIVE_LOCAL_DATA_CONNECTION_MODE &amp;&amp;<a name="line.784"></a>
<span class="sourceLineNo">785</span>                __dataConnectionMode != PASSIVE_LOCAL_DATA_CONNECTION_MODE) {<a name="line.785"></a>
<span class="sourceLineNo">786</span>            return null;<a name="line.786"></a>
<span class="sourceLineNo">787</span>        }<a name="line.787"></a>
<span class="sourceLineNo">788</span><a name="line.788"></a>
<span class="sourceLineNo">789</span>        final boolean isInet6Address = getRemoteAddress() instanceof Inet6Address;<a name="line.789"></a>
<span class="sourceLineNo">790</span><a name="line.790"></a>
<span class="sourceLineNo">791</span>        Socket socket;<a name="line.791"></a>
<span class="sourceLineNo">792</span><a name="line.792"></a>
<span class="sourceLineNo">793</span>        if (__dataConnectionMode == ACTIVE_LOCAL_DATA_CONNECTION_MODE)<a name="line.793"></a>
<span class="sourceLineNo">794</span>        {<a name="line.794"></a>
<span class="sourceLineNo">795</span>            // if no activePortRange was set (correctly) -&gt; getActivePort() = 0<a name="line.795"></a>
<span class="sourceLineNo">796</span>            // -&gt; new ServerSocket(0) -&gt; bind to any free local port<a name="line.796"></a>
<span class="sourceLineNo">797</span>            ServerSocket server = _serverSocketFactory_.createServerSocket(getActivePort(), 1, getHostAddress());<a name="line.797"></a>
<span class="sourceLineNo">798</span><a name="line.798"></a>
<span class="sourceLineNo">799</span>            try {<a name="line.799"></a>
<span class="sourceLineNo">800</span>                // Try EPRT only if remote server is over IPv6, if not use PORT,<a name="line.800"></a>
<span class="sourceLineNo">801</span>                // because EPRT has no advantage over PORT on IPv4.<a name="line.801"></a>
<span class="sourceLineNo">802</span>                // It could even have the disadvantage,<a name="line.802"></a>
<span class="sourceLineNo">803</span>                // that EPRT will make the data connection fail, because<a name="line.803"></a>
<span class="sourceLineNo">804</span>                // today's intelligent NAT Firewalls are able to<a name="line.804"></a>
<span class="sourceLineNo">805</span>                // substitute IP addresses in the PORT command,<a name="line.805"></a>
<span class="sourceLineNo">806</span>                // but might not be able to recognize the EPRT command.<a name="line.806"></a>
<span class="sourceLineNo">807</span>                if (isInet6Address) {<a name="line.807"></a>
<span class="sourceLineNo">808</span>                    if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort()))) {<a name="line.808"></a>
<span class="sourceLineNo">809</span>                        return null;<a name="line.809"></a>
<span class="sourceLineNo">810</span>                    }<a name="line.810"></a>
<span class="sourceLineNo">811</span>                } else {<a name="line.811"></a>
<span class="sourceLineNo">812</span>                    if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort()))) {<a name="line.812"></a>
<span class="sourceLineNo">813</span>                        return null;<a name="line.813"></a>
<span class="sourceLineNo">814</span>                    }<a name="line.814"></a>
<span class="sourceLineNo">815</span>                }<a name="line.815"></a>
<span class="sourceLineNo">816</span><a name="line.816"></a>
<span class="sourceLineNo">817</span>                if ((__restartOffset &gt; 0) &amp;&amp; !restart(__restartOffset)) {<a name="line.817"></a>
<span class="sourceLineNo">818</span>                    return null;<a name="line.818"></a>
<span class="sourceLineNo">819</span>                }<a name="line.819"></a>
<span class="sourceLineNo">820</span><a name="line.820"></a>
<span class="sourceLineNo">821</span>                if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {<a name="line.821"></a>
<span class="sourceLineNo">822</span>                    return null;<a name="line.822"></a>
<span class="sourceLineNo">823</span>                }<a name="line.823"></a>
<span class="sourceLineNo">824</span><a name="line.824"></a>
<span class="sourceLineNo">825</span>                // For now, let's just use the data timeout value for waiting for<a name="line.825"></a>
<span class="sourceLineNo">826</span>                // the data connection.  It may be desirable to let this be a<a name="line.826"></a>
<span class="sourceLineNo">827</span>                // separately configurable value.  In any case, we really want<a name="line.827"></a>
<span class="sourceLineNo">828</span>                // to allow preventing the accept from blocking indefinitely.<a name="line.828"></a>
<span class="sourceLineNo">829</span>                if (__dataTimeout &gt;= 0) {<a name="line.829"></a>
<span class="sourceLineNo">830</span>                    server.setSoTimeout(__dataTimeout);<a name="line.830"></a>
<span class="sourceLineNo">831</span>                }<a name="line.831"></a>
<span class="sourceLineNo">832</span>                socket = server.accept();<a name="line.832"></a>
<span class="sourceLineNo">833</span><a name="line.833"></a>
<span class="sourceLineNo">834</span>                // Ensure the timeout is set before any commands are issued on the new socket<a name="line.834"></a>
<span class="sourceLineNo">835</span>                if (__dataTimeout &gt;= 0) {<a name="line.835"></a>
<span class="sourceLineNo">836</span>                    socket.setSoTimeout(__dataTimeout);<a name="line.836"></a>
<span class="sourceLineNo">837</span>                }<a name="line.837"></a>
<span class="sourceLineNo">838</span>                if (__receiveDataSocketBufferSize &gt; 0) {<a name="line.838"></a>
<span class="sourceLineNo">839</span>                    socket.setReceiveBufferSize(__receiveDataSocketBufferSize);<a name="line.839"></a>
<span class="sourceLineNo">840</span>                }<a name="line.840"></a>
<span class="sourceLineNo">841</span>                if (__sendDataSocketBufferSize &gt; 0) {<a name="line.841"></a>
<span class="sourceLineNo">842</span>                    socket.setSendBufferSize(__sendDataSocketBufferSize);<a name="line.842"></a>
<span class="sourceLineNo">843</span>                }<a name="line.843"></a>
<span class="sourceLineNo">844</span>            } finally {<a name="line.844"></a>
<span class="sourceLineNo">845</span>                server.close();<a name="line.845"></a>
<span class="sourceLineNo">846</span>            }<a name="line.846"></a>
<span class="sourceLineNo">847</span>        }<a name="line.847"></a>
<span class="sourceLineNo">848</span>        else<a name="line.848"></a>
<span class="sourceLineNo">849</span>        { // We must be in PASSIVE_LOCAL_DATA_CONNECTION_MODE<a name="line.849"></a>
<span class="sourceLineNo">850</span><a name="line.850"></a>
<span class="sourceLineNo">851</span>            // Try EPSV command first on IPv6 - and IPv4 if enabled.<a name="line.851"></a>
<span class="sourceLineNo">852</span>            // When using IPv4 with NAT it has the advantage<a name="line.852"></a>
<span class="sourceLineNo">853</span>            // to work with more rare configurations.<a name="line.853"></a>
<span class="sourceLineNo">854</span>            // E.g. if FTP server has a static PASV address (external network)<a name="line.854"></a>
<span class="sourceLineNo">855</span>            // and the client is coming from another internal network.<a name="line.855"></a>
<span class="sourceLineNo">856</span>            // In that case the data connection after PASV command would fail,<a name="line.856"></a>
<span class="sourceLineNo">857</span>            // while EPSV would make the client succeed by taking just the port.<a name="line.857"></a>
<span class="sourceLineNo">858</span>            boolean attemptEPSV = isUseEPSVwithIPv4() || isInet6Address;<a name="line.858"></a>
<span class="sourceLineNo">859</span>            if (attemptEPSV &amp;&amp; epsv() == FTPReply.ENTERING_EPSV_MODE)<a name="line.859"></a>
<span class="sourceLineNo">860</span>            {<a name="line.860"></a>
<span class="sourceLineNo">861</span>                _parseExtendedPassiveModeReply(_replyLines.get(0));<a name="line.861"></a>
<span class="sourceLineNo">862</span>            }<a name="line.862"></a>
<span class="sourceLineNo">863</span>            else<a name="line.863"></a>
<span class="sourceLineNo">864</span>            {<a name="line.864"></a>
<span class="sourceLineNo">865</span>                if (isInet6Address) {<a name="line.865"></a>
<span class="sourceLineNo">866</span>                    return null; // Must use EPSV for IPV6<a name="line.866"></a>
<span class="sourceLineNo">867</span>                }<a name="line.867"></a>
<span class="sourceLineNo">868</span>                // If EPSV failed on IPV4, revert to PASV<a name="line.868"></a>
<span class="sourceLineNo">869</span>                if (pasv() != FTPReply.ENTERING_PASSIVE_MODE) {<a name="line.869"></a>
<span class="sourceLineNo">870</span>                    return null;<a name="line.870"></a>
<span class="sourceLineNo">871</span>                }<a name="line.871"></a>
<span class="sourceLineNo">872</span>                _parsePassiveModeReply(_replyLines.get(0));<a name="line.872"></a>
<span class="sourceLineNo">873</span>            }<a name="line.873"></a>
<span class="sourceLineNo">874</span><a name="line.874"></a>
<span class="sourceLineNo">875</span>            socket = _socketFactory_.createSocket();<a name="line.875"></a>
<span class="sourceLineNo">876</span>            if (__receiveDataSocketBufferSize &gt; 0) {<a name="line.876"></a>
<span class="sourceLineNo">877</span>                socket.setReceiveBufferSize(__receiveDataSocketBufferSize);<a name="line.877"></a>
<span class="sourceLineNo">878</span>            }<a name="line.878"></a>
<span class="sourceLineNo">879</span>            if (__sendDataSocketBufferSize &gt; 0) {<a name="line.879"></a>
<span class="sourceLineNo">880</span>                socket.setSendBufferSize(__sendDataSocketBufferSize);<a name="line.880"></a>
<span class="sourceLineNo">881</span>            }<a name="line.881"></a>
<span class="sourceLineNo">882</span>            if (__passiveLocalHost != null) {<a name="line.882"></a>
<span class="sourceLineNo">883</span>                socket.bind(new InetSocketAddress(__passiveLocalHost, 0));<a name="line.883"></a>
<span class="sourceLineNo">884</span>            }<a name="line.884"></a>
<span class="sourceLineNo">885</span><a name="line.885"></a>
<span class="sourceLineNo">886</span>            // For now, let's just use the data timeout value for waiting for<a name="line.886"></a>
<span class="sourceLineNo">887</span>            // the data connection.  It may be desirable to let this be a<a name="line.887"></a>
<span class="sourceLineNo">888</span>            // separately configurable value.  In any case, we really want<a name="line.888"></a>
<span class="sourceLineNo">889</span>            // to allow preventing the accept from blocking indefinitely.<a name="line.889"></a>
<span class="sourceLineNo">890</span>            if (__dataTimeout &gt;= 0) {<a name="line.890"></a>
<span class="sourceLineNo">891</span>                socket.setSoTimeout(__dataTimeout);<a name="line.891"></a>
<span class="sourceLineNo">892</span>            }<a name="line.892"></a>
<span class="sourceLineNo">893</span><a name="line.893"></a>
<span class="sourceLineNo">894</span>            socket.connect(new InetSocketAddress(__passiveHost, __passivePort), connectTimeout);<a name="line.894"></a>
<span class="sourceLineNo">895</span>            if ((__restartOffset &gt; 0) &amp;&amp; !restart(__restartOffset))<a name="line.895"></a>
<span class="sourceLineNo">896</span>            {<a name="line.896"></a>
<span class="sourceLineNo">897</span>                socket.close();<a name="line.897"></a>
<span class="sourceLineNo">898</span>                return null;<a name="line.898"></a>
<span class="sourceLineNo">899</span>            }<a name="line.899"></a>
<span class="sourceLineNo">900</span><a name="line.900"></a>
<span class="sourceLineNo">901</span>            if (!FTPReply.isPositivePreliminary(sendCommand(command, arg)))<a name="line.901"></a>
<span class="sourceLineNo">902</span>            {<a name="line.902"></a>
<span class="sourceLineNo">903</span>                socket.close();<a name="line.903"></a>
<span class="sourceLineNo">904</span>                return null;<a name="line.904"></a>
<span class="sourceLineNo">905</span>            }<a name="line.905"></a>
<span class="sourceLineNo">906</span>        }<a name="line.906"></a>
<span class="sourceLineNo">907</span><a name="line.907"></a>
<span class="sourceLineNo">908</span>        if (__remoteVerificationEnabled &amp;&amp; !verifyRemote(socket))<a name="line.908"></a>
<span class="sourceLineNo">909</span>        {<a name="line.909"></a>
<span class="sourceLineNo">910</span>            socket.close();<a name="line.910"></a>
<span class="sourceLineNo">911</span><a name="line.911"></a>
<span class="sourceLineNo">912</span>            throw new IOException(<a name="line.912"></a>
<span class="sourceLineNo">913</span>                    "Host attempting data connection " + socket.getInetAddress().getHostAddress() +<a name="line.913"></a>
<span class="sourceLineNo">914</span>                    " is not same as server " + getRemoteAddress().getHostAddress());<a name="line.914"></a>
<span class="sourceLineNo">915</span>        }<a name="line.915"></a>
<span class="sourceLineNo">916</span><a name="line.916"></a>
<span class="sourceLineNo">917</span>        return socket;<a name="line.917"></a>
<span class="sourceLineNo">918</span>    }<a name="line.918"></a>
<span class="sourceLineNo">919</span><a name="line.919"></a>
<span class="sourceLineNo">920</span><a name="line.920"></a>
<span class="sourceLineNo">921</span>    @Override<a name="line.921"></a>
<span class="sourceLineNo">922</span>    protected void _connectAction_() throws IOException<a name="line.922"></a>
<span class="sourceLineNo">923</span>    {<a name="line.923"></a>
<span class="sourceLineNo">924</span>        super._connectAction_(); // sets up _input_ and _output_<a name="line.924"></a>
<span class="sourceLineNo">925</span>        __initDefaults();<a name="line.925"></a>
<span class="sourceLineNo">926</span>        // must be after super._connectAction_(), because otherwise we get an<a name="line.926"></a>
<span class="sourceLineNo">927</span>        // Exception claiming we're not connected<a name="line.927"></a>
<span class="sourceLineNo">928</span>        if ( __autodetectEncoding )<a name="line.928"></a>
<span class="sourceLineNo">929</span>        {<a name="line.929"></a>
<span class="sourceLineNo">930</span>            ArrayList&lt;String&gt; oldReplyLines = new ArrayList&lt;String&gt; (_replyLines);<a name="line.930"></a>
<span class="sourceLineNo">931</span>            int oldReplyCode = _replyCode;<a name="line.931"></a>
<span class="sourceLineNo">932</span>            if ( hasFeature("UTF8") || hasFeature("UTF-8")) // UTF8 appears to be the default<a name="line.932"></a>
<span class="sourceLineNo">933</span>            {<a name="line.933"></a>
<span class="sourceLineNo">934</span>                 setControlEncoding("UTF-8");<a name="line.934"></a>
<span class="sourceLineNo">935</span>                 _controlInput_ =<a name="line.935"></a>
<span class="sourceLineNo">936</span>                     new CRLFLineReader(new InputStreamReader(_input_, getControlEncoding()));<a name="line.936"></a>
<span class="sourceLineNo">937</span>                 _controlOutput_ =<a name="line.937"></a>
<span class="sourceLineNo">938</span>                    new BufferedWriter(new OutputStreamWriter(_output_, getControlEncoding()));<a name="line.938"></a>
<span class="sourceLineNo">939</span>            }<a name="line.939"></a>
<span class="sourceLineNo">940</span>            // restore the original reply (server greeting)<a name="line.940"></a>
<span class="sourceLineNo">941</span>            _replyLines.clear();<a name="line.941"></a>
<span class="sourceLineNo">942</span>            _replyLines.addAll(oldReplyLines);<a name="line.942"></a>
<span class="sourceLineNo">943</span>            _replyCode = oldReplyCode;<a name="line.943"></a>
<span class="sourceLineNo">944</span>        }<a name="line.944"></a>
<span class="sourceLineNo">945</span>    }<a name="line.945"></a>
<span class="sourceLineNo">946</span><a name="line.946"></a>
<span class="sourceLineNo">947</span><a name="line.947"></a>
<span class="sourceLineNo">948</span>    /**<a name="line.948"></a>
<span class="sourceLineNo">949</span>     * Sets the timeout in milliseconds to use when reading from the<a name="line.949"></a>
<span class="sourceLineNo">950</span>     * data connection.  This timeout will be set immediately after<a name="line.950"></a>
<span class="sourceLineNo">951</span>     * opening the data connection, provided that the value is &amp;ge; 0.<a name="line.951"></a>
<span class="sourceLineNo">952</span>     * &lt;p&gt;<a name="line.952"></a>
<span class="sourceLineNo">953</span>     * &lt;b&gt;Note:&lt;/b&gt; the timeout will also be applied when calling accept()<a name="line.953"></a>
<span class="sourceLineNo">954</span>     * whilst establishing an active local data connection.<a name="line.954"></a>
<span class="sourceLineNo">955</span>     * @param  timeout The default timeout in milliseconds that is used when<a name="line.955"></a>
<span class="sourceLineNo">956</span>     *        opening a data connection socket. The value 0 means an infinite timeout.<a name="line.956"></a>
<span class="sourceLineNo">957</span>     */<a name="line.957"></a>
<span class="sourceLineNo">958</span>    public void setDataTimeout(int timeout)<a name="line.958"></a>
<span class="sourceLineNo">959</span>    {<a name="line.959"></a>
<span class="sourceLineNo">960</span>        __dataTimeout = timeout;<a name="line.960"></a>
<span class="sourceLineNo">961</span>    }<a name="line.961"></a>
<span class="sourceLineNo">962</span><a name="line.962"></a>
<span class="sourceLineNo">963</span>    /**<a name="line.963"></a>
<span class="sourceLineNo">964</span>     * set the factory used for parser creation to the supplied factory object.<a name="line.964"></a>
<span class="sourceLineNo">965</span>     *<a name="line.965"></a>
<span class="sourceLineNo">966</span>     * @param parserFactory<a name="line.966"></a>
<span class="sourceLineNo">967</span>     *               factory object used to create FTPFileEntryParsers<a name="line.967"></a>
<span class="sourceLineNo">968</span>     *<a name="line.968"></a>
<span class="sourceLineNo">969</span>     * @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory<a name="line.969"></a>
<span class="sourceLineNo">970</span>     * @see org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory<a name="line.970"></a>
<span class="sourceLineNo">971</span>     */<a name="line.971"></a>
<span class="sourceLineNo">972</span>    public void setParserFactory(FTPFileEntryParserFactory parserFactory) {<a name="line.972"></a>
<span class="sourceLineNo">973</span>        __parserFactory = parserFactory;<a name="line.973"></a>
<span class="sourceLineNo">974</span>    }<a name="line.974"></a>
<span class="sourceLineNo">975</span><a name="line.975"></a>
<span class="sourceLineNo">976</span><a name="line.976"></a>
<span class="sourceLineNo">977</span>    /**<a name="line.977"></a>
<span class="sourceLineNo">978</span>     * Closes the connection to the FTP server and restores<a name="line.978"></a>
<span class="sourceLineNo">979</span>     * connection parameters to the default values.<a name="line.979"></a>
<span class="sourceLineNo">980</span>     * &lt;p&gt;<a name="line.980"></a>
<span class="sourceLineNo">981</span>     * @exception IOException If an error occurs while disconnecting.<a name="line.981"></a>
<span class="sourceLineNo">982</span>     */<a name="line.982"></a>
<span class="sourceLineNo">983</span>    @Override<a name="line.983"></a>
<span class="sourceLineNo">984</span>    public void disconnect() throws IOException<a name="line.984"></a>
<span class="sourceLineNo">985</span>    {<a name="line.985"></a>
<span class="sourceLineNo">986</span>        super.disconnect();<a name="line.986"></a>
<span class="sourceLineNo">987</span>        __initDefaults();<a name="line.987"></a>
<span class="sourceLineNo">988</span>    }<a name="line.988"></a>
<span class="sourceLineNo">989</span><a name="line.989"></a>
<span class="sourceLineNo">990</span><a name="line.990"></a>
<span class="sourceLineNo">991</span>    /**<a name="line.991"></a>
<span class="sourceLineNo">992</span>     * Enable or disable verification that the remote host taking part<a name="line.992"></a>
<span class="sourceLineNo">993</span>     * of a data connection is the same as the host to which the control<a name="line.993"></a>
<span class="sourceLineNo">994</span>     * connection is attached.  The default is for verification to be<a name="line.994"></a>
<span class="sourceLineNo">995</span>     * enabled.  You may set this value at any time, whether the<a name="line.995"></a>
<span class="sourceLineNo">996</span>     * FTPClient is currently connected or not.<a name="line.996"></a>
<span class="sourceLineNo">997</span>     * &lt;p&gt;<a name="line.997"></a>
<span class="sourceLineNo">998</span>     * @param enable True to enable verification, false to disable verification.<a name="line.998"></a>
<span class="sourceLineNo">999</span>     */<a name="line.999"></a>
<span class="sourceLineNo">1000</span>    public void setRemoteVerificationEnabled(boolean enable)<a name="line.1000"></a>
<span class="sourceLineNo">1001</span>    {<a name="line.1001"></a>
<span class="sourceLineNo">1002</span>        __remoteVerificationEnabled = enable;<a name="line.1002"></a>
<span class="sourceLineNo">1003</span>    }<a name="line.1003"></a>
<span class="sourceLineNo">1004</span><a name="line.1004"></a>
<span class="sourceLineNo">1005</span>    /**<a name="line.1005"></a>
<span class="sourceLineNo">1006</span>     * Return whether or not verification of the remote host participating<a name="line.1006"></a>
<span class="sourceLineNo">1007</span>     * in data connections is enabled.  The default behavior is for<a name="line.1007"></a>
<span class="sourceLineNo">1008</span>     * verification to be enabled.<a name="line.1008"></a>
<span class="sourceLineNo">1009</span>     * &lt;p&gt;<a name="line.1009"></a>
<span class="sourceLineNo">1010</span>     * @return True if verification is enabled, false if not.<a name="line.1010"></a>
<span class="sourceLineNo">1011</span>     */<a name="line.1011"></a>
<span class="sourceLineNo">1012</span>    public boolean isRemoteVerificationEnabled()<a name="line.1012"></a>
<span class="sourceLineNo">1013</span>    {<a name="line.1013"></a>
<span class="sourceLineNo">1014</span>        return __remoteVerificationEnabled;<a name="line.1014"></a>
<span class="sourceLineNo">1015</span>    }<a name="line.1015"></a>
<span class="sourceLineNo">1016</span><a name="line.1016"></a>
<span class="sourceLineNo">1017</span>    /**<a name="line.1017"></a>
<span class="sourceLineNo">1018</span>     * Login to the FTP server using the provided username and password.<a name="line.1018"></a>
<span class="sourceLineNo">1019</span>     * &lt;p&gt;<a name="line.1019"></a>
<span class="sourceLineNo">1020</span>     * @param username The username to login under.<a name="line.1020"></a>
<span class="sourceLineNo">1021</span>     * @param password The password to use.<a name="line.1021"></a>
<span class="sourceLineNo">1022</span>     * @return True if successfully completed, false if not.<a name="line.1022"></a>
<span class="sourceLineNo">1023</span>     * @exception FTPConnectionClosedException<a name="line.1023"></a>
<span class="sourceLineNo">1024</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1024"></a>
<span class="sourceLineNo">1025</span>     *      of the client being idle or some other reason causing the server<a name="line.1025"></a>
<span class="sourceLineNo">1026</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1026"></a>
<span class="sourceLineNo">1027</span>     *      as an IOException or independently as itself.<a name="line.1027"></a>
<span class="sourceLineNo">1028</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1028"></a>
<span class="sourceLineNo">1029</span>     *      command to the server or receiving a reply from the server.<a name="line.1029"></a>
<span class="sourceLineNo">1030</span>     */<a name="line.1030"></a>
<span class="sourceLineNo">1031</span>    public boolean login(String username, String password) throws IOException<a name="line.1031"></a>
<span class="sourceLineNo">1032</span>    {<a name="line.1032"></a>
<span class="sourceLineNo">1033</span><a name="line.1033"></a>
<span class="sourceLineNo">1034</span>        user(username);<a name="line.1034"></a>
<span class="sourceLineNo">1035</span><a name="line.1035"></a>
<span class="sourceLineNo">1036</span>        if (FTPReply.isPositiveCompletion(_replyCode)) {<a name="line.1036"></a>
<span class="sourceLineNo">1037</span>            return true;<a name="line.1037"></a>
<span class="sourceLineNo">1038</span>        }<a name="line.1038"></a>
<span class="sourceLineNo">1039</span><a name="line.1039"></a>
<span class="sourceLineNo">1040</span>        // If we get here, we either have an error code, or an intermmediate<a name="line.1040"></a>
<span class="sourceLineNo">1041</span>        // reply requesting password.<a name="line.1041"></a>
<span class="sourceLineNo">1042</span>        if (!FTPReply.isPositiveIntermediate(_replyCode)) {<a name="line.1042"></a>
<span class="sourceLineNo">1043</span>            return false;<a name="line.1043"></a>
<span class="sourceLineNo">1044</span>        }<a name="line.1044"></a>
<span class="sourceLineNo">1045</span><a name="line.1045"></a>
<span class="sourceLineNo">1046</span>        return FTPReply.isPositiveCompletion(pass(password));<a name="line.1046"></a>
<span class="sourceLineNo">1047</span>    }<a name="line.1047"></a>
<span class="sourceLineNo">1048</span><a name="line.1048"></a>
<span class="sourceLineNo">1049</span><a name="line.1049"></a>
<span class="sourceLineNo">1050</span>    /**<a name="line.1050"></a>
<span class="sourceLineNo">1051</span>     * Login to the FTP server using the provided username, password,<a name="line.1051"></a>
<span class="sourceLineNo">1052</span>     * and account.  If no account is required by the server, only<a name="line.1052"></a>
<span class="sourceLineNo">1053</span>     * the username and password, the account information is not used.<a name="line.1053"></a>
<span class="sourceLineNo">1054</span>     * &lt;p&gt;<a name="line.1054"></a>
<span class="sourceLineNo">1055</span>     * @param username The username to login under.<a name="line.1055"></a>
<span class="sourceLineNo">1056</span>     * @param password The password to use.<a name="line.1056"></a>
<span class="sourceLineNo">1057</span>     * @param account  The account to use.<a name="line.1057"></a>
<span class="sourceLineNo">1058</span>     * @return True if successfully completed, false if not.<a name="line.1058"></a>
<span class="sourceLineNo">1059</span>     * @exception FTPConnectionClosedException<a name="line.1059"></a>
<span class="sourceLineNo">1060</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1060"></a>
<span class="sourceLineNo">1061</span>     *      of the client being idle or some other reason causing the server<a name="line.1061"></a>
<span class="sourceLineNo">1062</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1062"></a>
<span class="sourceLineNo">1063</span>     *      as an IOException or independently as itself.<a name="line.1063"></a>
<span class="sourceLineNo">1064</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1064"></a>
<span class="sourceLineNo">1065</span>     *      command to the server or receiving a reply from the server.<a name="line.1065"></a>
<span class="sourceLineNo">1066</span>     */<a name="line.1066"></a>
<span class="sourceLineNo">1067</span>    public boolean login(String username, String password, String account)<a name="line.1067"></a>
<span class="sourceLineNo">1068</span>    throws IOException<a name="line.1068"></a>
<span class="sourceLineNo">1069</span>    {<a name="line.1069"></a>
<span class="sourceLineNo">1070</span>        user(username);<a name="line.1070"></a>
<span class="sourceLineNo">1071</span><a name="line.1071"></a>
<span class="sourceLineNo">1072</span>        if (FTPReply.isPositiveCompletion(_replyCode)) {<a name="line.1072"></a>
<span class="sourceLineNo">1073</span>            return true;<a name="line.1073"></a>
<span class="sourceLineNo">1074</span>        }<a name="line.1074"></a>
<span class="sourceLineNo">1075</span><a name="line.1075"></a>
<span class="sourceLineNo">1076</span>        // If we get here, we either have an error code, or an intermmediate<a name="line.1076"></a>
<span class="sourceLineNo">1077</span>        // reply requesting password.<a name="line.1077"></a>
<span class="sourceLineNo">1078</span>        if (!FTPReply.isPositiveIntermediate(_replyCode)) {<a name="line.1078"></a>
<span class="sourceLineNo">1079</span>            return false;<a name="line.1079"></a>
<span class="sourceLineNo">1080</span>        }<a name="line.1080"></a>
<span class="sourceLineNo">1081</span><a name="line.1081"></a>
<span class="sourceLineNo">1082</span>        pass(password);<a name="line.1082"></a>
<span class="sourceLineNo">1083</span><a name="line.1083"></a>
<span class="sourceLineNo">1084</span>        if (FTPReply.isPositiveCompletion(_replyCode)) {<a name="line.1084"></a>
<span class="sourceLineNo">1085</span>            return true;<a name="line.1085"></a>
<span class="sourceLineNo">1086</span>        }<a name="line.1086"></a>
<span class="sourceLineNo">1087</span><a name="line.1087"></a>
<span class="sourceLineNo">1088</span>        if (!FTPReply.isPositiveIntermediate(_replyCode)) {<a name="line.1088"></a>
<span class="sourceLineNo">1089</span>            return false;<a name="line.1089"></a>
<span class="sourceLineNo">1090</span>        }<a name="line.1090"></a>
<span class="sourceLineNo">1091</span><a name="line.1091"></a>
<span class="sourceLineNo">1092</span>        return FTPReply.isPositiveCompletion(acct(account));<a name="line.1092"></a>
<span class="sourceLineNo">1093</span>    }<a name="line.1093"></a>
<span class="sourceLineNo">1094</span><a name="line.1094"></a>
<span class="sourceLineNo">1095</span>    /**<a name="line.1095"></a>
<span class="sourceLineNo">1096</span>     * Logout of the FTP server by sending the QUIT command.<a name="line.1096"></a>
<span class="sourceLineNo">1097</span>     * &lt;p&gt;<a name="line.1097"></a>
<span class="sourceLineNo">1098</span>     * @return True if successfully completed, false if not.<a name="line.1098"></a>
<span class="sourceLineNo">1099</span>     * @exception FTPConnectionClosedException<a name="line.1099"></a>
<span class="sourceLineNo">1100</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1100"></a>
<span class="sourceLineNo">1101</span>     *      of the client being idle or some other reason causing the server<a name="line.1101"></a>
<span class="sourceLineNo">1102</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1102"></a>
<span class="sourceLineNo">1103</span>     *      as an IOException or independently as itself.<a name="line.1103"></a>
<span class="sourceLineNo">1104</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1104"></a>
<span class="sourceLineNo">1105</span>     *      command to the server or receiving a reply from the server.<a name="line.1105"></a>
<span class="sourceLineNo">1106</span>     */<a name="line.1106"></a>
<span class="sourceLineNo">1107</span>    public boolean logout() throws IOException<a name="line.1107"></a>
<span class="sourceLineNo">1108</span>    {<a name="line.1108"></a>
<span class="sourceLineNo">1109</span>        return FTPReply.isPositiveCompletion(quit());<a name="line.1109"></a>
<span class="sourceLineNo">1110</span>    }<a name="line.1110"></a>
<span class="sourceLineNo">1111</span><a name="line.1111"></a>
<span class="sourceLineNo">1112</span><a name="line.1112"></a>
<span class="sourceLineNo">1113</span>    /**<a name="line.1113"></a>
<span class="sourceLineNo">1114</span>     * Change the current working directory of the FTP session.<a name="line.1114"></a>
<span class="sourceLineNo">1115</span>     * &lt;p&gt;<a name="line.1115"></a>
<span class="sourceLineNo">1116</span>     * @param pathname  The new current working directory.<a name="line.1116"></a>
<span class="sourceLineNo">1117</span>     * @return True if successfully completed, false if not.<a name="line.1117"></a>
<span class="sourceLineNo">1118</span>     * @exception FTPConnectionClosedException<a name="line.1118"></a>
<span class="sourceLineNo">1119</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1119"></a>
<span class="sourceLineNo">1120</span>     *      of the client being idle or some other reason causing the server<a name="line.1120"></a>
<span class="sourceLineNo">1121</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1121"></a>
<span class="sourceLineNo">1122</span>     *      as an IOException or independently as itself.<a name="line.1122"></a>
<span class="sourceLineNo">1123</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1123"></a>
<span class="sourceLineNo">1124</span>     *      command to the server or receiving a reply from the server.<a name="line.1124"></a>
<span class="sourceLineNo">1125</span>     */<a name="line.1125"></a>
<span class="sourceLineNo">1126</span>    public boolean changeWorkingDirectory(String pathname) throws IOException<a name="line.1126"></a>
<span class="sourceLineNo">1127</span>    {<a name="line.1127"></a>
<span class="sourceLineNo">1128</span>        return FTPReply.isPositiveCompletion(cwd(pathname));<a name="line.1128"></a>
<span class="sourceLineNo">1129</span>    }<a name="line.1129"></a>
<span class="sourceLineNo">1130</span><a name="line.1130"></a>
<span class="sourceLineNo">1131</span><a name="line.1131"></a>
<span class="sourceLineNo">1132</span>    /**<a name="line.1132"></a>
<span class="sourceLineNo">1133</span>     * Change to the parent directory of the current working directory.<a name="line.1133"></a>
<span class="sourceLineNo">1134</span>     * &lt;p&gt;<a name="line.1134"></a>
<span class="sourceLineNo">1135</span>     * @return True if successfully completed, false if not.<a name="line.1135"></a>
<span class="sourceLineNo">1136</span>     * @exception FTPConnectionClosedException<a name="line.1136"></a>
<span class="sourceLineNo">1137</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1137"></a>
<span class="sourceLineNo">1138</span>     *      of the client being idle or some other reason causing the server<a name="line.1138"></a>
<span class="sourceLineNo">1139</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1139"></a>
<span class="sourceLineNo">1140</span>     *      as an IOException or independently as itself.<a name="line.1140"></a>
<span class="sourceLineNo">1141</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1141"></a>
<span class="sourceLineNo">1142</span>     *      command to the server or receiving a reply from the server.<a name="line.1142"></a>
<span class="sourceLineNo">1143</span>     */<a name="line.1143"></a>
<span class="sourceLineNo">1144</span>    public boolean changeToParentDirectory() throws IOException<a name="line.1144"></a>
<span class="sourceLineNo">1145</span>    {<a name="line.1145"></a>
<span class="sourceLineNo">1146</span>        return FTPReply.isPositiveCompletion(cdup());<a name="line.1146"></a>
<span class="sourceLineNo">1147</span>    }<a name="line.1147"></a>
<span class="sourceLineNo">1148</span><a name="line.1148"></a>
<span class="sourceLineNo">1149</span><a name="line.1149"></a>
<span class="sourceLineNo">1150</span>    /**<a name="line.1150"></a>
<span class="sourceLineNo">1151</span>     * Issue the FTP SMNT command.<a name="line.1151"></a>
<span class="sourceLineNo">1152</span>     * &lt;p&gt;<a name="line.1152"></a>
<span class="sourceLineNo">1153</span>     * @param pathname The pathname to mount.<a name="line.1153"></a>
<span class="sourceLineNo">1154</span>     * @return True if successfully completed, false if not.<a name="line.1154"></a>
<span class="sourceLineNo">1155</span>     * @exception FTPConnectionClosedException<a name="line.1155"></a>
<span class="sourceLineNo">1156</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1156"></a>
<span class="sourceLineNo">1157</span>     *      of the client being idle or some other reason causing the server<a name="line.1157"></a>
<span class="sourceLineNo">1158</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1158"></a>
<span class="sourceLineNo">1159</span>     *      as an IOException or independently as itself.<a name="line.1159"></a>
<span class="sourceLineNo">1160</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1160"></a>
<span class="sourceLineNo">1161</span>     *      command to the server or receiving a reply from the server.<a name="line.1161"></a>
<span class="sourceLineNo">1162</span>     */<a name="line.1162"></a>
<span class="sourceLineNo">1163</span>    public boolean structureMount(String pathname) throws IOException<a name="line.1163"></a>
<span class="sourceLineNo">1164</span>    {<a name="line.1164"></a>
<span class="sourceLineNo">1165</span>        return FTPReply.isPositiveCompletion(smnt(pathname));<a name="line.1165"></a>
<span class="sourceLineNo">1166</span>    }<a name="line.1166"></a>
<span class="sourceLineNo">1167</span><a name="line.1167"></a>
<span class="sourceLineNo">1168</span>    /**<a name="line.1168"></a>
<span class="sourceLineNo">1169</span>     * Reinitialize the FTP session.  Not all FTP servers support this<a name="line.1169"></a>
<span class="sourceLineNo">1170</span>     * command, which issues the FTP REIN command.<a name="line.1170"></a>
<span class="sourceLineNo">1171</span>     * &lt;p&gt;<a name="line.1171"></a>
<span class="sourceLineNo">1172</span>     * @return True if successfully completed, false if not.<a name="line.1172"></a>
<span class="sourceLineNo">1173</span>     * @exception FTPConnectionClosedException<a name="line.1173"></a>
<span class="sourceLineNo">1174</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1174"></a>
<span class="sourceLineNo">1175</span>     *      of the client being idle or some other reason causing the server<a name="line.1175"></a>
<span class="sourceLineNo">1176</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1176"></a>
<span class="sourceLineNo">1177</span>     *      as an IOException or independently as itself.<a name="line.1177"></a>
<span class="sourceLineNo">1178</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1178"></a>
<span class="sourceLineNo">1179</span>     *      command to the server or receiving a reply from the server.<a name="line.1179"></a>
<span class="sourceLineNo">1180</span>     */<a name="line.1180"></a>
<span class="sourceLineNo">1181</span>    boolean reinitialize() throws IOException<a name="line.1181"></a>
<span class="sourceLineNo">1182</span>    {<a name="line.1182"></a>
<span class="sourceLineNo">1183</span>        rein();<a name="line.1183"></a>
<span class="sourceLineNo">1184</span><a name="line.1184"></a>
<span class="sourceLineNo">1185</span>        if (FTPReply.isPositiveCompletion(_replyCode) ||<a name="line.1185"></a>
<span class="sourceLineNo">1186</span>                (FTPReply.isPositivePreliminary(_replyCode) &amp;&amp;<a name="line.1186"></a>
<span class="sourceLineNo">1187</span>                        FTPReply.isPositiveCompletion(getReply())))<a name="line.1187"></a>
<span class="sourceLineNo">1188</span>        {<a name="line.1188"></a>
<span class="sourceLineNo">1189</span><a name="line.1189"></a>
<span class="sourceLineNo">1190</span>            __initDefaults();<a name="line.1190"></a>
<span class="sourceLineNo">1191</span><a name="line.1191"></a>
<span class="sourceLineNo">1192</span>            return true;<a name="line.1192"></a>
<span class="sourceLineNo">1193</span>        }<a name="line.1193"></a>
<span class="sourceLineNo">1194</span><a name="line.1194"></a>
<span class="sourceLineNo">1195</span>        return false;<a name="line.1195"></a>
<span class="sourceLineNo">1196</span>    }<a name="line.1196"></a>
<span class="sourceLineNo">1197</span><a name="line.1197"></a>
<span class="sourceLineNo">1198</span><a name="line.1198"></a>
<span class="sourceLineNo">1199</span>    /**<a name="line.1199"></a>
<span class="sourceLineNo">1200</span>     * Set the current data connection mode to<a name="line.1200"></a>
<span class="sourceLineNo">1201</span>     * &lt;code&gt;ACTIVE_LOCAL_DATA_CONNECTION_MODE&lt;/code&gt;.  No communication<a name="line.1201"></a>
<span class="sourceLineNo">1202</span>     * with the FTP server is conducted, but this causes all future data<a name="line.1202"></a>
<span class="sourceLineNo">1203</span>     * transfers to require the FTP server to connect to the client's<a name="line.1203"></a>
<span class="sourceLineNo">1204</span>     * data port.  Additionally, to accommodate differences between socket<a name="line.1204"></a>
<span class="sourceLineNo">1205</span>     * implementations on different platforms, this method causes the<a name="line.1205"></a>
<span class="sourceLineNo">1206</span>     * client to issue a PORT command before every data transfer.<a name="line.1206"></a>
<span class="sourceLineNo">1207</span>     */<a name="line.1207"></a>
<span class="sourceLineNo">1208</span>    public void enterLocalActiveMode()<a name="line.1208"></a>
<span class="sourceLineNo">1209</span>    {<a name="line.1209"></a>
<span class="sourceLineNo">1210</span>        __dataConnectionMode = ACTIVE_LOCAL_DATA_CONNECTION_MODE;<a name="line.1210"></a>
<span class="sourceLineNo">1211</span>        __passiveHost = null;<a name="line.1211"></a>
<span class="sourceLineNo">1212</span>        __passivePort = -1;<a name="line.1212"></a>
<span class="sourceLineNo">1213</span>    }<a name="line.1213"></a>
<span class="sourceLineNo">1214</span><a name="line.1214"></a>
<span class="sourceLineNo">1215</span><a name="line.1215"></a>
<span class="sourceLineNo">1216</span>    /**<a name="line.1216"></a>
<span class="sourceLineNo">1217</span>     * Set the current data connection mode to<a name="line.1217"></a>
<span class="sourceLineNo">1218</span>     * &lt;code&gt; PASSIVE_LOCAL_DATA_CONNECTION_MODE &lt;/code&gt;.  Use this<a name="line.1218"></a>
<span class="sourceLineNo">1219</span>     * method only for data transfers between the client and server.<a name="line.1219"></a>
<span class="sourceLineNo">1220</span>     * This method causes a PASV (or EPSV) command to be issued to the server<a name="line.1220"></a>
<span class="sourceLineNo">1221</span>     * before the opening of every data connection, telling the server to<a name="line.1221"></a>
<span class="sourceLineNo">1222</span>     * open a data port to which the client will connect to conduct<a name="line.1222"></a>
<span class="sourceLineNo">1223</span>     * data transfers.  The FTPClient will stay in<a name="line.1223"></a>
<span class="sourceLineNo">1224</span>     * &lt;code&gt; PASSIVE_LOCAL_DATA_CONNECTION_MODE &lt;/code&gt; until the<a name="line.1224"></a>
<span class="sourceLineNo">1225</span>     * mode is changed by calling some other method such as<a name="line.1225"></a>
<span class="sourceLineNo">1226</span>     * {@link #enterLocalActiveMode  enterLocalActiveMode() }<a name="line.1226"></a>
<span class="sourceLineNo">1227</span>     * &lt;p&gt;<a name="line.1227"></a>
<span class="sourceLineNo">1228</span>     * &lt;b&gt;N.B.&lt;/b&gt; currently calling any connect method will reset the mode to<a name="line.1228"></a>
<span class="sourceLineNo">1229</span>     * ACTIVE_LOCAL_DATA_CONNECTION_MODE.<a name="line.1229"></a>
<span class="sourceLineNo">1230</span>     */<a name="line.1230"></a>
<span class="sourceLineNo">1231</span>    public void enterLocalPassiveMode()<a name="line.1231"></a>
<span class="sourceLineNo">1232</span>    {<a name="line.1232"></a>
<span class="sourceLineNo">1233</span>        __dataConnectionMode = PASSIVE_LOCAL_DATA_CONNECTION_MODE;<a name="line.1233"></a>
<span class="sourceLineNo">1234</span>        // These will be set when just before a data connection is opened<a name="line.1234"></a>
<span class="sourceLineNo">1235</span>        // in _openDataConnection_()<a name="line.1235"></a>
<span class="sourceLineNo">1236</span>        __passiveHost = null;<a name="line.1236"></a>
<span class="sourceLineNo">1237</span>        __passivePort = -1;<a name="line.1237"></a>
<span class="sourceLineNo">1238</span>    }<a name="line.1238"></a>
<span class="sourceLineNo">1239</span><a name="line.1239"></a>
<span class="sourceLineNo">1240</span><a name="line.1240"></a>
<span class="sourceLineNo">1241</span>    /**<a name="line.1241"></a>
<span class="sourceLineNo">1242</span>     * Set the current data connection mode to<a name="line.1242"></a>
<span class="sourceLineNo">1243</span>     * &lt;code&gt; ACTIVE_REMOTE_DATA_CONNECTION &lt;/code&gt;.  Use this method only<a name="line.1243"></a>
<span class="sourceLineNo">1244</span>     * for server to server data transfers.  This method issues a PORT<a name="line.1244"></a>
<span class="sourceLineNo">1245</span>     * command to the server, indicating the other server and port to which<a name="line.1245"></a>
<span class="sourceLineNo">1246</span>     * it should connect for data transfers.  You must call this method<a name="line.1246"></a>
<span class="sourceLineNo">1247</span>     * before EVERY server to server transfer attempt.  The FTPClient will<a name="line.1247"></a>
<span class="sourceLineNo">1248</span>     * NOT automatically continue to issue PORT commands.  You also<a name="line.1248"></a>
<span class="sourceLineNo">1249</span>     * must remember to call<a name="line.1249"></a>
<span class="sourceLineNo">1250</span>     * {@link #enterLocalActiveMode  enterLocalActiveMode() } if you<a name="line.1250"></a>
<span class="sourceLineNo">1251</span>     * wish to return to the normal data connection mode.<a name="line.1251"></a>
<span class="sourceLineNo">1252</span>     * &lt;p&gt;<a name="line.1252"></a>
<span class="sourceLineNo">1253</span>     * @param host The passive mode server accepting connections for data<a name="line.1253"></a>
<span class="sourceLineNo">1254</span>     *             transfers.<a name="line.1254"></a>
<span class="sourceLineNo">1255</span>     * @param port The passive mode server's data port.<a name="line.1255"></a>
<span class="sourceLineNo">1256</span>     * @return True if successfully completed, false if not.<a name="line.1256"></a>
<span class="sourceLineNo">1257</span>     * @exception FTPConnectionClosedException<a name="line.1257"></a>
<span class="sourceLineNo">1258</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1258"></a>
<span class="sourceLineNo">1259</span>     *      of the client being idle or some other reason causing the server<a name="line.1259"></a>
<span class="sourceLineNo">1260</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1260"></a>
<span class="sourceLineNo">1261</span>     *      as an IOException or independently as itself.<a name="line.1261"></a>
<span class="sourceLineNo">1262</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1262"></a>
<span class="sourceLineNo">1263</span>     *      command to the server or receiving a reply from the server.<a name="line.1263"></a>
<span class="sourceLineNo">1264</span>     */<a name="line.1264"></a>
<span class="sourceLineNo">1265</span>    public boolean enterRemoteActiveMode(InetAddress host, int port)<a name="line.1265"></a>
<span class="sourceLineNo">1266</span>    throws IOException<a name="line.1266"></a>
<span class="sourceLineNo">1267</span>    {<a name="line.1267"></a>
<span class="sourceLineNo">1268</span>        if (FTPReply.isPositiveCompletion(port(host, port)))<a name="line.1268"></a>
<span class="sourceLineNo">1269</span>        {<a name="line.1269"></a>
<span class="sourceLineNo">1270</span>            __dataConnectionMode = ACTIVE_REMOTE_DATA_CONNECTION_MODE;<a name="line.1270"></a>
<span class="sourceLineNo">1271</span>            __passiveHost = null;<a name="line.1271"></a>
<span class="sourceLineNo">1272</span>            __passivePort = -1;<a name="line.1272"></a>
<span class="sourceLineNo">1273</span>            return true;<a name="line.1273"></a>
<span class="sourceLineNo">1274</span>        }<a name="line.1274"></a>
<span class="sourceLineNo">1275</span>        return false;<a name="line.1275"></a>
<span class="sourceLineNo">1276</span>    }<a name="line.1276"></a>
<span class="sourceLineNo">1277</span><a name="line.1277"></a>
<span class="sourceLineNo">1278</span>    /**<a name="line.1278"></a>
<span class="sourceLineNo">1279</span>     * Set the current data connection mode to<a name="line.1279"></a>
<span class="sourceLineNo">1280</span>     * &lt;code&gt; PASSIVE_REMOTE_DATA_CONNECTION_MODE &lt;/code&gt;.  Use this<a name="line.1280"></a>
<span class="sourceLineNo">1281</span>     * method only for server to server data transfers.<a name="line.1281"></a>
<span class="sourceLineNo">1282</span>     * This method issues a PASV command to the server, telling it to<a name="line.1282"></a>
<span class="sourceLineNo">1283</span>     * open a data port to which the active server will connect to conduct<a name="line.1283"></a>
<span class="sourceLineNo">1284</span>     * data transfers.  You must call this method<a name="line.1284"></a>
<span class="sourceLineNo">1285</span>     * before EVERY server to server transfer attempt.  The FTPClient will<a name="line.1285"></a>
<span class="sourceLineNo">1286</span>     * NOT automatically continue to issue PASV commands.  You also<a name="line.1286"></a>
<span class="sourceLineNo">1287</span>     * must remember to call<a name="line.1287"></a>
<span class="sourceLineNo">1288</span>     * {@link #enterLocalActiveMode  enterLocalActiveMode() } if you<a name="line.1288"></a>
<span class="sourceLineNo">1289</span>     * wish to return to the normal data connection mode.<a name="line.1289"></a>
<span class="sourceLineNo">1290</span>     * &lt;p&gt;<a name="line.1290"></a>
<span class="sourceLineNo">1291</span>     * @return True if successfully completed, false if not.<a name="line.1291"></a>
<span class="sourceLineNo">1292</span>     * @exception FTPConnectionClosedException<a name="line.1292"></a>
<span class="sourceLineNo">1293</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1293"></a>
<span class="sourceLineNo">1294</span>     *      of the client being idle or some other reason causing the server<a name="line.1294"></a>
<span class="sourceLineNo">1295</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1295"></a>
<span class="sourceLineNo">1296</span>     *      as an IOException or independently as itself.<a name="line.1296"></a>
<span class="sourceLineNo">1297</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1297"></a>
<span class="sourceLineNo">1298</span>     *      command to the server or receiving a reply from the server.<a name="line.1298"></a>
<span class="sourceLineNo">1299</span>     */<a name="line.1299"></a>
<span class="sourceLineNo">1300</span>    public boolean enterRemotePassiveMode() throws IOException<a name="line.1300"></a>
<span class="sourceLineNo">1301</span>    {<a name="line.1301"></a>
<span class="sourceLineNo">1302</span>        if (pasv() != FTPReply.ENTERING_PASSIVE_MODE) {<a name="line.1302"></a>
<span class="sourceLineNo">1303</span>            return false;<a name="line.1303"></a>
<span class="sourceLineNo">1304</span>        }<a name="line.1304"></a>
<span class="sourceLineNo">1305</span><a name="line.1305"></a>
<span class="sourceLineNo">1306</span>        __dataConnectionMode = PASSIVE_REMOTE_DATA_CONNECTION_MODE;<a name="line.1306"></a>
<span class="sourceLineNo">1307</span>        _parsePassiveModeReply(_replyLines.get(0));<a name="line.1307"></a>
<span class="sourceLineNo">1308</span><a name="line.1308"></a>
<span class="sourceLineNo">1309</span>        return true;<a name="line.1309"></a>
<span class="sourceLineNo">1310</span>    }<a name="line.1310"></a>
<span class="sourceLineNo">1311</span><a name="line.1311"></a>
<span class="sourceLineNo">1312</span>    /**<a name="line.1312"></a>
<span class="sourceLineNo">1313</span>     * Returns the hostname or IP address (in the form of a string) returned<a name="line.1313"></a>
<span class="sourceLineNo">1314</span>     * by the server when entering passive mode.  If not in passive mode,<a name="line.1314"></a>
<span class="sourceLineNo">1315</span>     * returns null.  This method only returns a valid value AFTER a<a name="line.1315"></a>
<span class="sourceLineNo">1316</span>     * data connection has been opened after a call to<a name="line.1316"></a>
<span class="sourceLineNo">1317</span>     * {@link #enterLocalPassiveMode enterLocalPassiveMode()}.<a name="line.1317"></a>
<span class="sourceLineNo">1318</span>     * This is because FTPClient sends a PASV command to the server only<a name="line.1318"></a>
<span class="sourceLineNo">1319</span>     * just before opening a data connection, and not when you call<a name="line.1319"></a>
<span class="sourceLineNo">1320</span>     * {@link #enterLocalPassiveMode enterLocalPassiveMode()}.<a name="line.1320"></a>
<span class="sourceLineNo">1321</span>     * &lt;p&gt;<a name="line.1321"></a>
<span class="sourceLineNo">1322</span>     * @return The passive host name if in passive mode, otherwise null.<a name="line.1322"></a>
<span class="sourceLineNo">1323</span>     */<a name="line.1323"></a>
<span class="sourceLineNo">1324</span>    public String getPassiveHost()<a name="line.1324"></a>
<span class="sourceLineNo">1325</span>    {<a name="line.1325"></a>
<span class="sourceLineNo">1326</span>        return __passiveHost;<a name="line.1326"></a>
<span class="sourceLineNo">1327</span>    }<a name="line.1327"></a>
<span class="sourceLineNo">1328</span><a name="line.1328"></a>
<span class="sourceLineNo">1329</span>    /**<a name="line.1329"></a>
<span class="sourceLineNo">1330</span>     * If in passive mode, returns the data port of the passive host.<a name="line.1330"></a>
<span class="sourceLineNo">1331</span>     * This method only returns a valid value AFTER a<a name="line.1331"></a>
<span class="sourceLineNo">1332</span>     * data connection has been opened after a call to<a name="line.1332"></a>
<span class="sourceLineNo">1333</span>     * {@link #enterLocalPassiveMode enterLocalPassiveMode()}.<a name="line.1333"></a>
<span class="sourceLineNo">1334</span>     * This is because FTPClient sends a PASV command to the server only<a name="line.1334"></a>
<span class="sourceLineNo">1335</span>     * just before opening a data connection, and not when you call<a name="line.1335"></a>
<span class="sourceLineNo">1336</span>     * {@link #enterLocalPassiveMode enterLocalPassiveMode()}.<a name="line.1336"></a>
<span class="sourceLineNo">1337</span>     * &lt;p&gt;<a name="line.1337"></a>
<span class="sourceLineNo">1338</span>     * @return The data port of the passive server.  If not in passive<a name="line.1338"></a>
<span class="sourceLineNo">1339</span>     *         mode, undefined.<a name="line.1339"></a>
<span class="sourceLineNo">1340</span>     */<a name="line.1340"></a>
<span class="sourceLineNo">1341</span>    public int getPassivePort()<a name="line.1341"></a>
<span class="sourceLineNo">1342</span>    {<a name="line.1342"></a>
<span class="sourceLineNo">1343</span>        return __passivePort;<a name="line.1343"></a>
<span class="sourceLineNo">1344</span>    }<a name="line.1344"></a>
<span class="sourceLineNo">1345</span><a name="line.1345"></a>
<span class="sourceLineNo">1346</span><a name="line.1346"></a>
<span class="sourceLineNo">1347</span>    /**<a name="line.1347"></a>
<span class="sourceLineNo">1348</span>     * Returns the current data connection mode (one of the<a name="line.1348"></a>
<span class="sourceLineNo">1349</span>     * &lt;code&gt; _DATA_CONNECTION_MODE &lt;/code&gt; constants.<a name="line.1349"></a>
<span class="sourceLineNo">1350</span>     * &lt;p&gt;<a name="line.1350"></a>
<span class="sourceLineNo">1351</span>     * @return The current data connection mode (one of the<a name="line.1351"></a>
<span class="sourceLineNo">1352</span>     * &lt;code&gt; _DATA_CONNECTION_MODE &lt;/code&gt; constants.<a name="line.1352"></a>
<span class="sourceLineNo">1353</span>     */<a name="line.1353"></a>
<span class="sourceLineNo">1354</span>    public int getDataConnectionMode()<a name="line.1354"></a>
<span class="sourceLineNo">1355</span>    {<a name="line.1355"></a>
<span class="sourceLineNo">1356</span>        return __dataConnectionMode;<a name="line.1356"></a>
<span class="sourceLineNo">1357</span>    }<a name="line.1357"></a>
<span class="sourceLineNo">1358</span><a name="line.1358"></a>
<span class="sourceLineNo">1359</span>    /**<a name="line.1359"></a>
<span class="sourceLineNo">1360</span>     * Get the client port for active mode.<a name="line.1360"></a>
<span class="sourceLineNo">1361</span>     * &lt;p&gt;<a name="line.1361"></a>
<span class="sourceLineNo">1362</span>     * @return The client port for active mode.<a name="line.1362"></a>
<span class="sourceLineNo">1363</span>     */<a name="line.1363"></a>
<span class="sourceLineNo">1364</span>    private int getActivePort()<a name="line.1364"></a>
<span class="sourceLineNo">1365</span>    {<a name="line.1365"></a>
<span class="sourceLineNo">1366</span>        if (__activeMinPort &gt; 0 &amp;&amp; __activeMaxPort &gt;= __activeMinPort)<a name="line.1366"></a>
<span class="sourceLineNo">1367</span>        {<a name="line.1367"></a>
<span class="sourceLineNo">1368</span>            if (__activeMaxPort == __activeMinPort) {<a name="line.1368"></a>
<span class="sourceLineNo">1369</span>                return __activeMaxPort;<a name="line.1369"></a>
<span class="sourceLineNo">1370</span>            }<a name="line.1370"></a>
<span class="sourceLineNo">1371</span>            // Get a random port between the min and max port range<a name="line.1371"></a>
<span class="sourceLineNo">1372</span>            return __random.nextInt(__activeMaxPort - __activeMinPort + 1) + __activeMinPort;<a name="line.1372"></a>
<span class="sourceLineNo">1373</span>        }<a name="line.1373"></a>
<span class="sourceLineNo">1374</span>        else<a name="line.1374"></a>
<span class="sourceLineNo">1375</span>        {<a name="line.1375"></a>
<span class="sourceLineNo">1376</span>            // default port<a name="line.1376"></a>
<span class="sourceLineNo">1377</span>            return 0;<a name="line.1377"></a>
<span class="sourceLineNo">1378</span>        }<a name="line.1378"></a>
<span class="sourceLineNo">1379</span>    }<a name="line.1379"></a>
<span class="sourceLineNo">1380</span><a name="line.1380"></a>
<span class="sourceLineNo">1381</span>    /**<a name="line.1381"></a>
<span class="sourceLineNo">1382</span>     * Get the host address for active mode; allows the local address to be overridden.<a name="line.1382"></a>
<span class="sourceLineNo">1383</span>     * &lt;p&gt;<a name="line.1383"></a>
<span class="sourceLineNo">1384</span>     * @return __activeExternalHost if non-null, else getLocalAddress()<a name="line.1384"></a>
<span class="sourceLineNo">1385</span>     * @see #setActiveExternalIPAddress(String)<a name="line.1385"></a>
<span class="sourceLineNo">1386</span>     */<a name="line.1386"></a>
<span class="sourceLineNo">1387</span>    private InetAddress getHostAddress()<a name="line.1387"></a>
<span class="sourceLineNo">1388</span>    {<a name="line.1388"></a>
<span class="sourceLineNo">1389</span>        if (__activeExternalHost != null)<a name="line.1389"></a>
<span class="sourceLineNo">1390</span>        {<a name="line.1390"></a>
<span class="sourceLineNo">1391</span>            return __activeExternalHost;<a name="line.1391"></a>
<span class="sourceLineNo">1392</span>        }<a name="line.1392"></a>
<span class="sourceLineNo">1393</span>        else<a name="line.1393"></a>
<span class="sourceLineNo">1394</span>        {<a name="line.1394"></a>
<span class="sourceLineNo">1395</span>            // default local address<a name="line.1395"></a>
<span class="sourceLineNo">1396</span>            return getLocalAddress();<a name="line.1396"></a>
<span class="sourceLineNo">1397</span>        }<a name="line.1397"></a>
<span class="sourceLineNo">1398</span>    }<a name="line.1398"></a>
<span class="sourceLineNo">1399</span><a name="line.1399"></a>
<span class="sourceLineNo">1400</span>    /**<a name="line.1400"></a>
<span class="sourceLineNo">1401</span>     * Get the reported host address for active mode EPRT/PORT commands;<a name="line.1401"></a>
<span class="sourceLineNo">1402</span>     * allows override of {@link #getHostAddress()}.<a name="line.1402"></a>
<span class="sourceLineNo">1403</span>     *<a name="line.1403"></a>
<span class="sourceLineNo">1404</span>     * Useful for FTP Client behind Firewall NAT.<a name="line.1404"></a>
<span class="sourceLineNo">1405</span>     * &lt;p&gt;<a name="line.1405"></a>
<span class="sourceLineNo">1406</span>     * @return __reportActiveExternalHost if non-null, else getHostAddress();<a name="line.1406"></a>
<span class="sourceLineNo">1407</span>     */<a name="line.1407"></a>
<span class="sourceLineNo">1408</span>    private InetAddress getReportHostAddress() {<a name="line.1408"></a>
<span class="sourceLineNo">1409</span>        if (__reportActiveExternalHost != null) {<a name="line.1409"></a>
<span class="sourceLineNo">1410</span>            return __reportActiveExternalHost ;<a name="line.1410"></a>
<span class="sourceLineNo">1411</span>        } else {<a name="line.1411"></a>
<span class="sourceLineNo">1412</span>            return getHostAddress();<a name="line.1412"></a>
<span class="sourceLineNo">1413</span>        }<a name="line.1413"></a>
<span class="sourceLineNo">1414</span>    }<a name="line.1414"></a>
<span class="sourceLineNo">1415</span><a name="line.1415"></a>
<span class="sourceLineNo">1416</span>    /**<a name="line.1416"></a>
<span class="sourceLineNo">1417</span>     * Set the client side port range in active mode.<a name="line.1417"></a>
<span class="sourceLineNo">1418</span>     * &lt;p&gt;<a name="line.1418"></a>
<span class="sourceLineNo">1419</span>     * @param minPort The lowest available port (inclusive).<a name="line.1419"></a>
<span class="sourceLineNo">1420</span>     * @param maxPort The highest available port (inclusive).<a name="line.1420"></a>
<span class="sourceLineNo">1421</span>     * @since 2.2<a name="line.1421"></a>
<span class="sourceLineNo">1422</span>     */<a name="line.1422"></a>
<span class="sourceLineNo">1423</span>    public void setActivePortRange(int minPort, int maxPort)<a name="line.1423"></a>
<span class="sourceLineNo">1424</span>    {<a name="line.1424"></a>
<span class="sourceLineNo">1425</span>        this.__activeMinPort = minPort;<a name="line.1425"></a>
<span class="sourceLineNo">1426</span>        this.__activeMaxPort = maxPort;<a name="line.1426"></a>
<span class="sourceLineNo">1427</span>    }<a name="line.1427"></a>
<span class="sourceLineNo">1428</span><a name="line.1428"></a>
<span class="sourceLineNo">1429</span>    /**<a name="line.1429"></a>
<span class="sourceLineNo">1430</span>     * Set the external IP address in active mode.<a name="line.1430"></a>
<span class="sourceLineNo">1431</span>     * Useful when there are multiple network cards.<a name="line.1431"></a>
<span class="sourceLineNo">1432</span>     * &lt;p&gt;<a name="line.1432"></a>
<span class="sourceLineNo">1433</span>     * @param ipAddress The external IP address of this machine.<a name="line.1433"></a>
<span class="sourceLineNo">1434</span>     * @throws UnknownHostException if the ipAddress cannot be resolved<a name="line.1434"></a>
<span class="sourceLineNo">1435</span>     * @since 2.2<a name="line.1435"></a>
<span class="sourceLineNo">1436</span>     */<a name="line.1436"></a>
<span class="sourceLineNo">1437</span>    public void setActiveExternalIPAddress(String ipAddress) throws UnknownHostException<a name="line.1437"></a>
<span class="sourceLineNo">1438</span>    {<a name="line.1438"></a>
<span class="sourceLineNo">1439</span>        this.__activeExternalHost = InetAddress.getByName(ipAddress);<a name="line.1439"></a>
<span class="sourceLineNo">1440</span>    }<a name="line.1440"></a>
<span class="sourceLineNo">1441</span><a name="line.1441"></a>
<span class="sourceLineNo">1442</span>    /**<a name="line.1442"></a>
<span class="sourceLineNo">1443</span>     * Set the local IP address to use in passive mode.<a name="line.1443"></a>
<span class="sourceLineNo">1444</span>     * Useful when there are multiple network cards.<a name="line.1444"></a>
<span class="sourceLineNo">1445</span>     * &lt;p&gt;<a name="line.1445"></a>
<span class="sourceLineNo">1446</span>     * @param ipAddress The local IP address of this machine.<a name="line.1446"></a>
<span class="sourceLineNo">1447</span>     * @throws UnknownHostException if the ipAddress cannot be resolved<a name="line.1447"></a>
<span class="sourceLineNo">1448</span>     */<a name="line.1448"></a>
<span class="sourceLineNo">1449</span>    public void setPassiveLocalIPAddress(String ipAddress) throws UnknownHostException<a name="line.1449"></a>
<span class="sourceLineNo">1450</span>    {<a name="line.1450"></a>
<span class="sourceLineNo">1451</span>        this.__passiveLocalHost = InetAddress.getByName(ipAddress);<a name="line.1451"></a>
<span class="sourceLineNo">1452</span>    }<a name="line.1452"></a>
<span class="sourceLineNo">1453</span><a name="line.1453"></a>
<span class="sourceLineNo">1454</span>    /**<a name="line.1454"></a>
<span class="sourceLineNo">1455</span>     * Set the local IP address to use in passive mode.<a name="line.1455"></a>
<span class="sourceLineNo">1456</span>     * Useful when there are multiple network cards.<a name="line.1456"></a>
<span class="sourceLineNo">1457</span>     * &lt;p&gt;<a name="line.1457"></a>
<span class="sourceLineNo">1458</span>     * @param inetAddress The local IP address of this machine.<a name="line.1458"></a>
<span class="sourceLineNo">1459</span>     */<a name="line.1459"></a>
<span class="sourceLineNo">1460</span>    public void setPassiveLocalIPAddress(InetAddress inetAddress)<a name="line.1460"></a>
<span class="sourceLineNo">1461</span>    {<a name="line.1461"></a>
<span class="sourceLineNo">1462</span>        this.__passiveLocalHost = inetAddress;<a name="line.1462"></a>
<span class="sourceLineNo">1463</span>    }<a name="line.1463"></a>
<span class="sourceLineNo">1464</span><a name="line.1464"></a>
<span class="sourceLineNo">1465</span>    /**<a name="line.1465"></a>
<span class="sourceLineNo">1466</span>     * Set the local IP address in passive mode.<a name="line.1466"></a>
<span class="sourceLineNo">1467</span>     * Useful when there are multiple network cards.<a name="line.1467"></a>
<span class="sourceLineNo">1468</span>     * &lt;p&gt;<a name="line.1468"></a>
<span class="sourceLineNo">1469</span>     * @return The local IP address in passive mode.<a name="line.1469"></a>
<span class="sourceLineNo">1470</span>     */<a name="line.1470"></a>
<span class="sourceLineNo">1471</span>    public InetAddress getPassiveLocalIPAddress()<a name="line.1471"></a>
<span class="sourceLineNo">1472</span>    {<a name="line.1472"></a>
<span class="sourceLineNo">1473</span>        return this.__passiveLocalHost;<a name="line.1473"></a>
<span class="sourceLineNo">1474</span>    }<a name="line.1474"></a>
<span class="sourceLineNo">1475</span><a name="line.1475"></a>
<span class="sourceLineNo">1476</span>    /**<a name="line.1476"></a>
<span class="sourceLineNo">1477</span>     * Set the external IP address to report in EPRT/PORT commands in active mode.<a name="line.1477"></a>
<span class="sourceLineNo">1478</span>     * Useful when there are multiple network cards.<a name="line.1478"></a>
<span class="sourceLineNo">1479</span>     * &lt;p&gt;<a name="line.1479"></a>
<span class="sourceLineNo">1480</span>     * @param ipAddress The external IP address of this machine.<a name="line.1480"></a>
<span class="sourceLineNo">1481</span>     * @throws UnknownHostException if the ipAddress cannot be resolved<a name="line.1481"></a>
<span class="sourceLineNo">1482</span>     * @since 3.1<a name="line.1482"></a>
<span class="sourceLineNo">1483</span>     * @see #getReportHostAddress()<a name="line.1483"></a>
<span class="sourceLineNo">1484</span>     */<a name="line.1484"></a>
<span class="sourceLineNo">1485</span>    public void setReportActiveExternalIPAddress(String ipAddress) throws UnknownHostException<a name="line.1485"></a>
<span class="sourceLineNo">1486</span>    {<a name="line.1486"></a>
<span class="sourceLineNo">1487</span>        this.__reportActiveExternalHost = InetAddress.getByName(ipAddress);<a name="line.1487"></a>
<span class="sourceLineNo">1488</span>    }<a name="line.1488"></a>
<span class="sourceLineNo">1489</span><a name="line.1489"></a>
<span class="sourceLineNo">1490</span><a name="line.1490"></a>
<span class="sourceLineNo">1491</span>    /**<a name="line.1491"></a>
<span class="sourceLineNo">1492</span>     * Sets the file type to be transferred.  This should be one of<a name="line.1492"></a>
<span class="sourceLineNo">1493</span>     * &lt;code&gt; FTP.ASCII_FILE_TYPE &lt;/code&gt;, &lt;code&gt; FTP.BINARY_FILE_TYPE&lt;/code&gt;,<a name="line.1493"></a>
<span class="sourceLineNo">1494</span>     * etc.  The file type only needs to be set when you want to change the<a name="line.1494"></a>
<span class="sourceLineNo">1495</span>     * type.  After changing it, the new type stays in effect until you change<a name="line.1495"></a>
<span class="sourceLineNo">1496</span>     * it again.  The default file type is &lt;code&gt; FTP.ASCII_FILE_TYPE &lt;/code&gt;<a name="line.1496"></a>
<span class="sourceLineNo">1497</span>     * if this method is never called.<a name="line.1497"></a>
<span class="sourceLineNo">1498</span>     * &lt;br&gt;<a name="line.1498"></a>
<span class="sourceLineNo">1499</span>     * The server default is supposed to be ASCII (see RFC 959), however many<a name="line.1499"></a>
<span class="sourceLineNo">1500</span>     * ftp servers default to BINARY. &lt;b&gt;To ensure correct operation with all servers,<a name="line.1500"></a>
<span class="sourceLineNo">1501</span>     * always specify the appropriate file type after connecting to the server.&lt;/b&gt;<a name="line.1501"></a>
<span class="sourceLineNo">1502</span>     * &lt;br&gt;<a name="line.1502"></a>
<span class="sourceLineNo">1503</span>     * &lt;p&gt;<a name="line.1503"></a>
<span class="sourceLineNo">1504</span>     * &lt;b&gt;N.B.&lt;/b&gt; currently calling any connect method will reset the type to<a name="line.1504"></a>
<span class="sourceLineNo">1505</span>     * FTP.ASCII_FILE_TYPE.<a name="line.1505"></a>
<span class="sourceLineNo">1506</span>     * @param fileType The &lt;code&gt; _FILE_TYPE &lt;/code&gt; constant indcating the<a name="line.1506"></a>
<span class="sourceLineNo">1507</span>     *                 type of file.<a name="line.1507"></a>
<span class="sourceLineNo">1508</span>     * @return True if successfully completed, false if not.<a name="line.1508"></a>
<span class="sourceLineNo">1509</span>     * @exception FTPConnectionClosedException<a name="line.1509"></a>
<span class="sourceLineNo">1510</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1510"></a>
<span class="sourceLineNo">1511</span>     *      of the client being idle or some other reason causing the server<a name="line.1511"></a>
<span class="sourceLineNo">1512</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1512"></a>
<span class="sourceLineNo">1513</span>     *      as an IOException or independently as itself.<a name="line.1513"></a>
<span class="sourceLineNo">1514</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1514"></a>
<span class="sourceLineNo">1515</span>     *      command to the server or receiving a reply from the server.<a name="line.1515"></a>
<span class="sourceLineNo">1516</span>     */<a name="line.1516"></a>
<span class="sourceLineNo">1517</span>    public boolean setFileType(int fileType) throws IOException<a name="line.1517"></a>
<span class="sourceLineNo">1518</span>    {<a name="line.1518"></a>
<span class="sourceLineNo">1519</span>        if (FTPReply.isPositiveCompletion(type(fileType)))<a name="line.1519"></a>
<span class="sourceLineNo">1520</span>        {<a name="line.1520"></a>
<span class="sourceLineNo">1521</span>            __fileType = fileType;<a name="line.1521"></a>
<span class="sourceLineNo">1522</span>            __fileFormat = FTP.NON_PRINT_TEXT_FORMAT;<a name="line.1522"></a>
<span class="sourceLineNo">1523</span>            return true;<a name="line.1523"></a>
<span class="sourceLineNo">1524</span>        }<a name="line.1524"></a>
<span class="sourceLineNo">1525</span>        return false;<a name="line.1525"></a>
<span class="sourceLineNo">1526</span>    }<a name="line.1526"></a>
<span class="sourceLineNo">1527</span><a name="line.1527"></a>
<span class="sourceLineNo">1528</span><a name="line.1528"></a>
<span class="sourceLineNo">1529</span>    /**<a name="line.1529"></a>
<span class="sourceLineNo">1530</span>     * Sets the file type to be transferred and the format.  The type should be<a name="line.1530"></a>
<span class="sourceLineNo">1531</span>     * one of  &lt;code&gt; FTP.ASCII_FILE_TYPE &lt;/code&gt;,<a name="line.1531"></a>
<span class="sourceLineNo">1532</span>     * &lt;code&gt; FTP.BINARY_FILE_TYPE &lt;/code&gt;, etc.  The file type only needs to<a name="line.1532"></a>
<span class="sourceLineNo">1533</span>     * be set when you want to change the type.  After changing it, the new<a name="line.1533"></a>
<span class="sourceLineNo">1534</span>     * type stays in effect until you change it again.  The default file type<a name="line.1534"></a>
<span class="sourceLineNo">1535</span>     * is &lt;code&gt; FTP.ASCII_FILE_TYPE &lt;/code&gt; if this method is never called.<a name="line.1535"></a>
<span class="sourceLineNo">1536</span>     * &lt;br&gt;<a name="line.1536"></a>
<span class="sourceLineNo">1537</span>     * The server default is supposed to be ASCII (see RFC 959), however many<a name="line.1537"></a>
<span class="sourceLineNo">1538</span>     * ftp servers default to BINARY. &lt;b&gt;To ensure correct operation with all servers,<a name="line.1538"></a>
<span class="sourceLineNo">1539</span>     * always specify the appropriate file type after connecting to the server.&lt;/b&gt;<a name="line.1539"></a>
<span class="sourceLineNo">1540</span>     * &lt;br&gt;<a name="line.1540"></a>
<span class="sourceLineNo">1541</span>     * The format should be one of the FTP class &lt;code&gt; TEXT_FORMAT &lt;/code&gt;<a name="line.1541"></a>
<span class="sourceLineNo">1542</span>     * constants, or if the type is &lt;code&gt; FTP.LOCAL_FILE_TYPE &lt;/code&gt;, the<a name="line.1542"></a>
<span class="sourceLineNo">1543</span>     * format should be the byte size for that type.  The default format<a name="line.1543"></a>
<span class="sourceLineNo">1544</span>     * is &lt;code&gt; FTP.NON_PRINT_TEXT_FORMAT &lt;/code&gt; if this method is never<a name="line.1544"></a>
<span class="sourceLineNo">1545</span>     * called.<a name="line.1545"></a>
<span class="sourceLineNo">1546</span>     * &lt;p&gt;<a name="line.1546"></a>
<span class="sourceLineNo">1547</span>     * &lt;b&gt;N.B.&lt;/b&gt; currently calling any connect method will reset the type to<a name="line.1547"></a>
<span class="sourceLineNo">1548</span>     * FTP.ASCII_FILE_TYPE and the formatOrByteSize to FTP.NON_PRINT_TEXT_FORMAT.<a name="line.1548"></a>
<span class="sourceLineNo">1549</span>     * &lt;p&gt;<a name="line.1549"></a>
<span class="sourceLineNo">1550</span>     * @param fileType The &lt;code&gt; _FILE_TYPE &lt;/code&gt; constant indcating the<a name="line.1550"></a>
<span class="sourceLineNo">1551</span>     *                 type of file.<a name="line.1551"></a>
<span class="sourceLineNo">1552</span>     * @param formatOrByteSize  The format of the file (one of the<a name="line.1552"></a>
<span class="sourceLineNo">1553</span>     *              &lt;code&gt;_FORMAT&lt;/code&gt; constants.  In the case of<a name="line.1553"></a>
<span class="sourceLineNo">1554</span>     *              &lt;code&gt;LOCAL_FILE_TYPE&lt;/code&gt;, the byte size.<a name="line.1554"></a>
<span class="sourceLineNo">1555</span>     * &lt;p&gt;<a name="line.1555"></a>
<span class="sourceLineNo">1556</span>     * @return True if successfully completed, false if not.<a name="line.1556"></a>
<span class="sourceLineNo">1557</span>     * @exception FTPConnectionClosedException<a name="line.1557"></a>
<span class="sourceLineNo">1558</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1558"></a>
<span class="sourceLineNo">1559</span>     *      of the client being idle or some other reason causing the server<a name="line.1559"></a>
<span class="sourceLineNo">1560</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1560"></a>
<span class="sourceLineNo">1561</span>     *      as an IOException or independently as itself.<a name="line.1561"></a>
<span class="sourceLineNo">1562</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1562"></a>
<span class="sourceLineNo">1563</span>     *      command to the server or receiving a reply from the server.<a name="line.1563"></a>
<span class="sourceLineNo">1564</span>     */<a name="line.1564"></a>
<span class="sourceLineNo">1565</span>    public boolean setFileType(int fileType, int formatOrByteSize)<a name="line.1565"></a>
<span class="sourceLineNo">1566</span>    throws IOException<a name="line.1566"></a>
<span class="sourceLineNo">1567</span>    {<a name="line.1567"></a>
<span class="sourceLineNo">1568</span>        if (FTPReply.isPositiveCompletion(type(fileType, formatOrByteSize)))<a name="line.1568"></a>
<span class="sourceLineNo">1569</span>        {<a name="line.1569"></a>
<span class="sourceLineNo">1570</span>            __fileType = fileType;<a name="line.1570"></a>
<span class="sourceLineNo">1571</span>            __fileFormat = formatOrByteSize;<a name="line.1571"></a>
<span class="sourceLineNo">1572</span>            return true;<a name="line.1572"></a>
<span class="sourceLineNo">1573</span>        }<a name="line.1573"></a>
<span class="sourceLineNo">1574</span>        return false;<a name="line.1574"></a>
<span class="sourceLineNo">1575</span>    }<a name="line.1575"></a>
<span class="sourceLineNo">1576</span><a name="line.1576"></a>
<span class="sourceLineNo">1577</span><a name="line.1577"></a>
<span class="sourceLineNo">1578</span>    /**<a name="line.1578"></a>
<span class="sourceLineNo">1579</span>     * Sets the file structure.  The default structure is<a name="line.1579"></a>
<span class="sourceLineNo">1580</span>     * &lt;code&gt; FTP.FILE_STRUCTURE &lt;/code&gt; if this method is never called<a name="line.1580"></a>
<span class="sourceLineNo">1581</span>     * or if a connect method is called.<a name="line.1581"></a>
<span class="sourceLineNo">1582</span>     * &lt;p&gt;<a name="line.1582"></a>
<span class="sourceLineNo">1583</span>     * @param structure  The structure of the file (one of the FTP class<a name="line.1583"></a>
<span class="sourceLineNo">1584</span>     *         &lt;code&gt;_STRUCTURE&lt;/code&gt; constants).<a name="line.1584"></a>
<span class="sourceLineNo">1585</span>     * @return True if successfully completed, false if not.<a name="line.1585"></a>
<span class="sourceLineNo">1586</span>     * @exception FTPConnectionClosedException<a name="line.1586"></a>
<span class="sourceLineNo">1587</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1587"></a>
<span class="sourceLineNo">1588</span>     *      of the client being idle or some other reason causing the server<a name="line.1588"></a>
<span class="sourceLineNo">1589</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1589"></a>
<span class="sourceLineNo">1590</span>     *      as an IOException or independently as itself.<a name="line.1590"></a>
<span class="sourceLineNo">1591</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1591"></a>
<span class="sourceLineNo">1592</span>     *      command to the server or receiving a reply from the server.<a name="line.1592"></a>
<span class="sourceLineNo">1593</span>     */<a name="line.1593"></a>
<span class="sourceLineNo">1594</span>    public boolean setFileStructure(int structure) throws IOException<a name="line.1594"></a>
<span class="sourceLineNo">1595</span>    {<a name="line.1595"></a>
<span class="sourceLineNo">1596</span>        if (FTPReply.isPositiveCompletion(stru(structure)))<a name="line.1596"></a>
<span class="sourceLineNo">1597</span>        {<a name="line.1597"></a>
<span class="sourceLineNo">1598</span>            __fileStructure = structure;<a name="line.1598"></a>
<span class="sourceLineNo">1599</span>            return true;<a name="line.1599"></a>
<span class="sourceLineNo">1600</span>        }<a name="line.1600"></a>
<span class="sourceLineNo">1601</span>        return false;<a name="line.1601"></a>
<span class="sourceLineNo">1602</span>    }<a name="line.1602"></a>
<span class="sourceLineNo">1603</span><a name="line.1603"></a>
<span class="sourceLineNo">1604</span><a name="line.1604"></a>
<span class="sourceLineNo">1605</span>    /**<a name="line.1605"></a>
<span class="sourceLineNo">1606</span>     * Sets the transfer mode.  The default transfer mode<a name="line.1606"></a>
<span class="sourceLineNo">1607</span>     * &lt;code&gt; FTP.STREAM_TRANSFER_MODE &lt;/code&gt; if this method is never called<a name="line.1607"></a>
<span class="sourceLineNo">1608</span>     * or if a connect method is called.<a name="line.1608"></a>
<span class="sourceLineNo">1609</span>     * &lt;p&gt;<a name="line.1609"></a>
<span class="sourceLineNo">1610</span>     * @param mode  The new transfer mode to use (one of the FTP class<a name="line.1610"></a>
<span class="sourceLineNo">1611</span>     *         &lt;code&gt;_TRANSFER_MODE&lt;/code&gt; constants).<a name="line.1611"></a>
<span class="sourceLineNo">1612</span>     * @return True if successfully completed, false if not.<a name="line.1612"></a>
<span class="sourceLineNo">1613</span>     * @exception FTPConnectionClosedException<a name="line.1613"></a>
<span class="sourceLineNo">1614</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1614"></a>
<span class="sourceLineNo">1615</span>     *      of the client being idle or some other reason causing the server<a name="line.1615"></a>
<span class="sourceLineNo">1616</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1616"></a>
<span class="sourceLineNo">1617</span>     *      as an IOException or independently as itself.<a name="line.1617"></a>
<span class="sourceLineNo">1618</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1618"></a>
<span class="sourceLineNo">1619</span>     *      command to the server or receiving a reply from the server.<a name="line.1619"></a>
<span class="sourceLineNo">1620</span>     */<a name="line.1620"></a>
<span class="sourceLineNo">1621</span>    public boolean setFileTransferMode(int mode) throws IOException<a name="line.1621"></a>
<span class="sourceLineNo">1622</span>    {<a name="line.1622"></a>
<span class="sourceLineNo">1623</span>        if (FTPReply.isPositiveCompletion(mode(mode)))<a name="line.1623"></a>
<span class="sourceLineNo">1624</span>        {<a name="line.1624"></a>
<span class="sourceLineNo">1625</span>            __fileTransferMode = mode;<a name="line.1625"></a>
<span class="sourceLineNo">1626</span>            return true;<a name="line.1626"></a>
<span class="sourceLineNo">1627</span>        }<a name="line.1627"></a>
<span class="sourceLineNo">1628</span>        return false;<a name="line.1628"></a>
<span class="sourceLineNo">1629</span>    }<a name="line.1629"></a>
<span class="sourceLineNo">1630</span><a name="line.1630"></a>
<span class="sourceLineNo">1631</span><a name="line.1631"></a>
<span class="sourceLineNo">1632</span>    /**<a name="line.1632"></a>
<span class="sourceLineNo">1633</span>     * Initiate a server to server file transfer.  This method tells the<a name="line.1633"></a>
<span class="sourceLineNo">1634</span>     * server to which the client is connected to retrieve a given file from<a name="line.1634"></a>
<span class="sourceLineNo">1635</span>     * the other server.<a name="line.1635"></a>
<span class="sourceLineNo">1636</span>     * &lt;p&gt;<a name="line.1636"></a>
<span class="sourceLineNo">1637</span>     * @param filename  The name of the file to retrieve.<a name="line.1637"></a>
<span class="sourceLineNo">1638</span>     * @return True if successfully completed, false if not.<a name="line.1638"></a>
<span class="sourceLineNo">1639</span>     * @exception FTPConnectionClosedException<a name="line.1639"></a>
<span class="sourceLineNo">1640</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1640"></a>
<span class="sourceLineNo">1641</span>     *      of the client being idle or some other reason causing the server<a name="line.1641"></a>
<span class="sourceLineNo">1642</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1642"></a>
<span class="sourceLineNo">1643</span>     *      as an IOException or independently as itself.<a name="line.1643"></a>
<span class="sourceLineNo">1644</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1644"></a>
<span class="sourceLineNo">1645</span>     *      command to the server or receiving a reply from the server.<a name="line.1645"></a>
<span class="sourceLineNo">1646</span>     */<a name="line.1646"></a>
<span class="sourceLineNo">1647</span>    public boolean remoteRetrieve(String filename) throws IOException<a name="line.1647"></a>
<span class="sourceLineNo">1648</span>    {<a name="line.1648"></a>
<span class="sourceLineNo">1649</span>        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||<a name="line.1649"></a>
<span class="sourceLineNo">1650</span>                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) {<a name="line.1650"></a>
<span class="sourceLineNo">1651</span>            return FTPReply.isPositivePreliminary(retr(filename));<a name="line.1651"></a>
<span class="sourceLineNo">1652</span>        }<a name="line.1652"></a>
<span class="sourceLineNo">1653</span>        return false;<a name="line.1653"></a>
<span class="sourceLineNo">1654</span>    }<a name="line.1654"></a>
<span class="sourceLineNo">1655</span><a name="line.1655"></a>
<span class="sourceLineNo">1656</span><a name="line.1656"></a>
<span class="sourceLineNo">1657</span>    /**<a name="line.1657"></a>
<span class="sourceLineNo">1658</span>     * Initiate a server to server file transfer.  This method tells the<a name="line.1658"></a>
<span class="sourceLineNo">1659</span>     * server to which the client is connected to store a file on<a name="line.1659"></a>
<span class="sourceLineNo">1660</span>     * the other server using the given filename.  The other server must<a name="line.1660"></a>
<span class="sourceLineNo">1661</span>     * have had a &lt;code&gt; remoteRetrieve &lt;/code&gt; issued to it by another<a name="line.1661"></a>
<span class="sourceLineNo">1662</span>     * FTPClient.<a name="line.1662"></a>
<span class="sourceLineNo">1663</span>     * &lt;p&gt;<a name="line.1663"></a>
<span class="sourceLineNo">1664</span>     * @param filename  The name to call the file that is to be stored.<a name="line.1664"></a>
<span class="sourceLineNo">1665</span>     * @return True if successfully completed, false if not.<a name="line.1665"></a>
<span class="sourceLineNo">1666</span>     * @exception FTPConnectionClosedException<a name="line.1666"></a>
<span class="sourceLineNo">1667</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1667"></a>
<span class="sourceLineNo">1668</span>     *      of the client being idle or some other reason causing the server<a name="line.1668"></a>
<span class="sourceLineNo">1669</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1669"></a>
<span class="sourceLineNo">1670</span>     *      as an IOException or independently as itself.<a name="line.1670"></a>
<span class="sourceLineNo">1671</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1671"></a>
<span class="sourceLineNo">1672</span>     *      command to the server or receiving a reply from the server.<a name="line.1672"></a>
<span class="sourceLineNo">1673</span>     */<a name="line.1673"></a>
<span class="sourceLineNo">1674</span>    public boolean remoteStore(String filename) throws IOException<a name="line.1674"></a>
<span class="sourceLineNo">1675</span>    {<a name="line.1675"></a>
<span class="sourceLineNo">1676</span>        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||<a name="line.1676"></a>
<span class="sourceLineNo">1677</span>                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) {<a name="line.1677"></a>
<span class="sourceLineNo">1678</span>            return FTPReply.isPositivePreliminary(stor(filename));<a name="line.1678"></a>
<span class="sourceLineNo">1679</span>        }<a name="line.1679"></a>
<span class="sourceLineNo">1680</span>        return false;<a name="line.1680"></a>
<span class="sourceLineNo">1681</span>    }<a name="line.1681"></a>
<span class="sourceLineNo">1682</span><a name="line.1682"></a>
<span class="sourceLineNo">1683</span><a name="line.1683"></a>
<span class="sourceLineNo">1684</span>    /**<a name="line.1684"></a>
<span class="sourceLineNo">1685</span>     * Initiate a server to server file transfer.  This method tells the<a name="line.1685"></a>
<span class="sourceLineNo">1686</span>     * server to which the client is connected to store a file on<a name="line.1686"></a>
<span class="sourceLineNo">1687</span>     * the other server using a unique filename based on the given filename.<a name="line.1687"></a>
<span class="sourceLineNo">1688</span>     * The other server must have had a &lt;code&gt; remoteRetrieve &lt;/code&gt; issued<a name="line.1688"></a>
<span class="sourceLineNo">1689</span>     * to it by another FTPClient.<a name="line.1689"></a>
<span class="sourceLineNo">1690</span>     * &lt;p&gt;<a name="line.1690"></a>
<span class="sourceLineNo">1691</span>     * @param filename  The name on which to base the filename of the file<a name="line.1691"></a>
<span class="sourceLineNo">1692</span>     *                  that is to be stored.<a name="line.1692"></a>
<span class="sourceLineNo">1693</span>     * @return True if successfully completed, false if not.<a name="line.1693"></a>
<span class="sourceLineNo">1694</span>     * @exception FTPConnectionClosedException<a name="line.1694"></a>
<span class="sourceLineNo">1695</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1695"></a>
<span class="sourceLineNo">1696</span>     *      of the client being idle or some other reason causing the server<a name="line.1696"></a>
<span class="sourceLineNo">1697</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1697"></a>
<span class="sourceLineNo">1698</span>     *      as an IOException or independently as itself.<a name="line.1698"></a>
<span class="sourceLineNo">1699</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1699"></a>
<span class="sourceLineNo">1700</span>     *      command to the server or receiving a reply from the server.<a name="line.1700"></a>
<span class="sourceLineNo">1701</span>     */<a name="line.1701"></a>
<span class="sourceLineNo">1702</span>    public boolean remoteStoreUnique(String filename) throws IOException<a name="line.1702"></a>
<span class="sourceLineNo">1703</span>    {<a name="line.1703"></a>
<span class="sourceLineNo">1704</span>        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||<a name="line.1704"></a>
<span class="sourceLineNo">1705</span>                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) {<a name="line.1705"></a>
<span class="sourceLineNo">1706</span>            return FTPReply.isPositivePreliminary(stou(filename));<a name="line.1706"></a>
<span class="sourceLineNo">1707</span>        }<a name="line.1707"></a>
<span class="sourceLineNo">1708</span>        return false;<a name="line.1708"></a>
<span class="sourceLineNo">1709</span>    }<a name="line.1709"></a>
<span class="sourceLineNo">1710</span><a name="line.1710"></a>
<span class="sourceLineNo">1711</span><a name="line.1711"></a>
<span class="sourceLineNo">1712</span>    /**<a name="line.1712"></a>
<span class="sourceLineNo">1713</span>     * Initiate a server to server file transfer.  This method tells the<a name="line.1713"></a>
<span class="sourceLineNo">1714</span>     * server to which the client is connected to store a file on<a name="line.1714"></a>
<span class="sourceLineNo">1715</span>     * the other server using a unique filename.<a name="line.1715"></a>
<span class="sourceLineNo">1716</span>     * The other server must have had a &lt;code&gt; remoteRetrieve &lt;/code&gt; issued<a name="line.1716"></a>
<span class="sourceLineNo">1717</span>     * to it by another FTPClient.  Many FTP servers require that a base<a name="line.1717"></a>
<span class="sourceLineNo">1718</span>     * filename be given from which the unique filename can be derived.  For<a name="line.1718"></a>
<span class="sourceLineNo">1719</span>     * those servers use the other version of &lt;code&gt; remoteStoreUnique&lt;/code&gt;<a name="line.1719"></a>
<span class="sourceLineNo">1720</span>     * &lt;p&gt;<a name="line.1720"></a>
<span class="sourceLineNo">1721</span>     * @return True if successfully completed, false if not.<a name="line.1721"></a>
<span class="sourceLineNo">1722</span>     * @exception FTPConnectionClosedException<a name="line.1722"></a>
<span class="sourceLineNo">1723</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1723"></a>
<span class="sourceLineNo">1724</span>     *      of the client being idle or some other reason causing the server<a name="line.1724"></a>
<span class="sourceLineNo">1725</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1725"></a>
<span class="sourceLineNo">1726</span>     *      as an IOException or independently as itself.<a name="line.1726"></a>
<span class="sourceLineNo">1727</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1727"></a>
<span class="sourceLineNo">1728</span>     *      command to the server or receiving a reply from the server.<a name="line.1728"></a>
<span class="sourceLineNo">1729</span>     */<a name="line.1729"></a>
<span class="sourceLineNo">1730</span>    public boolean remoteStoreUnique() throws IOException<a name="line.1730"></a>
<span class="sourceLineNo">1731</span>    {<a name="line.1731"></a>
<span class="sourceLineNo">1732</span>        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||<a name="line.1732"></a>
<span class="sourceLineNo">1733</span>                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) {<a name="line.1733"></a>
<span class="sourceLineNo">1734</span>            return FTPReply.isPositivePreliminary(stou());<a name="line.1734"></a>
<span class="sourceLineNo">1735</span>        }<a name="line.1735"></a>
<span class="sourceLineNo">1736</span>        return false;<a name="line.1736"></a>
<span class="sourceLineNo">1737</span>    }<a name="line.1737"></a>
<span class="sourceLineNo">1738</span><a name="line.1738"></a>
<span class="sourceLineNo">1739</span>    // For server to server transfers<a name="line.1739"></a>
<span class="sourceLineNo">1740</span>    /**<a name="line.1740"></a>
<span class="sourceLineNo">1741</span>     * Initiate a server to server file transfer.  This method tells the<a name="line.1741"></a>
<span class="sourceLineNo">1742</span>     * server to which the client is connected to append to a given file on<a name="line.1742"></a>
<span class="sourceLineNo">1743</span>     * the other server.  The other server must have had a<a name="line.1743"></a>
<span class="sourceLineNo">1744</span>     * &lt;code&gt; remoteRetrieve &lt;/code&gt; issued to it by another FTPClient.<a name="line.1744"></a>
<span class="sourceLineNo">1745</span>     * &lt;p&gt;<a name="line.1745"></a>
<span class="sourceLineNo">1746</span>     * @param filename  The name of the file to be appended to, or if the<a name="line.1746"></a>
<span class="sourceLineNo">1747</span>     *        file does not exist, the name to call the file being stored.<a name="line.1747"></a>
<span class="sourceLineNo">1748</span>     * &lt;p&gt;<a name="line.1748"></a>
<span class="sourceLineNo">1749</span>     * @return True if successfully completed, false if not.<a name="line.1749"></a>
<span class="sourceLineNo">1750</span>     * @exception FTPConnectionClosedException<a name="line.1750"></a>
<span class="sourceLineNo">1751</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1751"></a>
<span class="sourceLineNo">1752</span>     *      of the client being idle or some other reason causing the server<a name="line.1752"></a>
<span class="sourceLineNo">1753</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1753"></a>
<span class="sourceLineNo">1754</span>     *      as an IOException or independently as itself.<a name="line.1754"></a>
<span class="sourceLineNo">1755</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1755"></a>
<span class="sourceLineNo">1756</span>     *      command to the server or receiving a reply from the server.<a name="line.1756"></a>
<span class="sourceLineNo">1757</span>     */<a name="line.1757"></a>
<span class="sourceLineNo">1758</span>    public boolean remoteAppend(String filename) throws IOException<a name="line.1758"></a>
<span class="sourceLineNo">1759</span>    {<a name="line.1759"></a>
<span class="sourceLineNo">1760</span>        if (__dataConnectionMode == ACTIVE_REMOTE_DATA_CONNECTION_MODE ||<a name="line.1760"></a>
<span class="sourceLineNo">1761</span>                __dataConnectionMode == PASSIVE_REMOTE_DATA_CONNECTION_MODE) {<a name="line.1761"></a>
<span class="sourceLineNo">1762</span>            return FTPReply.isPositivePreliminary(appe(filename));<a name="line.1762"></a>
<span class="sourceLineNo">1763</span>        }<a name="line.1763"></a>
<span class="sourceLineNo">1764</span>        return false;<a name="line.1764"></a>
<span class="sourceLineNo">1765</span>    }<a name="line.1765"></a>
<span class="sourceLineNo">1766</span><a name="line.1766"></a>
<span class="sourceLineNo">1767</span>    /**<a name="line.1767"></a>
<span class="sourceLineNo">1768</span>     * There are a few FTPClient methods that do not complete the<a name="line.1768"></a>
<span class="sourceLineNo">1769</span>     * entire sequence of FTP commands to complete a transaction.  These<a name="line.1769"></a>
<span class="sourceLineNo">1770</span>     * commands require some action by the programmer after the reception<a name="line.1770"></a>
<span class="sourceLineNo">1771</span>     * of a positive intermediate command.  After the programmer's code<a name="line.1771"></a>
<span class="sourceLineNo">1772</span>     * completes its actions, it must call this method to receive<a name="line.1772"></a>
<span class="sourceLineNo">1773</span>     * the completion reply from the server and verify the success of the<a name="line.1773"></a>
<span class="sourceLineNo">1774</span>     * entire transaction.<a name="line.1774"></a>
<span class="sourceLineNo">1775</span>     * &lt;p&gt;<a name="line.1775"></a>
<span class="sourceLineNo">1776</span>     * For example,<a name="line.1776"></a>
<span class="sourceLineNo">1777</span>     * &lt;pre&gt;<a name="line.1777"></a>
<span class="sourceLineNo">1778</span>     * InputStream input;<a name="line.1778"></a>
<span class="sourceLineNo">1779</span>     * OutputStream output;<a name="line.1779"></a>
<span class="sourceLineNo">1780</span>     * input  = new FileInputStream("foobaz.txt");<a name="line.1780"></a>
<span class="sourceLineNo">1781</span>     * output = ftp.storeFileStream("foobar.txt")<a name="line.1781"></a>
<span class="sourceLineNo">1782</span>     * if(!FTPReply.isPositiveIntermediate(ftp.getReplyCode())) {<a name="line.1782"></a>
<span class="sourceLineNo">1783</span>     *     input.close();<a name="line.1783"></a>
<span class="sourceLineNo">1784</span>     *     output.close();<a name="line.1784"></a>
<span class="sourceLineNo">1785</span>     *     ftp.logout();<a name="line.1785"></a>
<span class="sourceLineNo">1786</span>     *     ftp.disconnect();<a name="line.1786"></a>
<span class="sourceLineNo">1787</span>     *     System.err.println("File transfer failed.");<a name="line.1787"></a>
<span class="sourceLineNo">1788</span>     *     System.exit(1);<a name="line.1788"></a>
<span class="sourceLineNo">1789</span>     * }<a name="line.1789"></a>
<span class="sourceLineNo">1790</span>     * Util.copyStream(input, output);<a name="line.1790"></a>
<span class="sourceLineNo">1791</span>     * input.close();<a name="line.1791"></a>
<span class="sourceLineNo">1792</span>     * output.close();<a name="line.1792"></a>
<span class="sourceLineNo">1793</span>     * // Must call completePendingCommand() to finish command.<a name="line.1793"></a>
<span class="sourceLineNo">1794</span>     * if(!ftp.completePendingCommand()) {<a name="line.1794"></a>
<span class="sourceLineNo">1795</span>     *     ftp.logout();<a name="line.1795"></a>
<span class="sourceLineNo">1796</span>     *     ftp.disconnect();<a name="line.1796"></a>
<span class="sourceLineNo">1797</span>     *     System.err.println("File transfer failed.");<a name="line.1797"></a>
<span class="sourceLineNo">1798</span>     *     System.exit(1);<a name="line.1798"></a>
<span class="sourceLineNo">1799</span>     * }<a name="line.1799"></a>
<span class="sourceLineNo">1800</span>     * &lt;/pre&gt;<a name="line.1800"></a>
<span class="sourceLineNo">1801</span>     * &lt;p&gt;<a name="line.1801"></a>
<span class="sourceLineNo">1802</span>     * @return True if successfully completed, false if not.<a name="line.1802"></a>
<span class="sourceLineNo">1803</span>     * @exception FTPConnectionClosedException<a name="line.1803"></a>
<span class="sourceLineNo">1804</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1804"></a>
<span class="sourceLineNo">1805</span>     *      of the client being idle or some other reason causing the server<a name="line.1805"></a>
<span class="sourceLineNo">1806</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1806"></a>
<span class="sourceLineNo">1807</span>     *      as an IOException or independently as itself.<a name="line.1807"></a>
<span class="sourceLineNo">1808</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1808"></a>
<span class="sourceLineNo">1809</span>     *      command to the server or receiving a reply from the server.<a name="line.1809"></a>
<span class="sourceLineNo">1810</span>     */<a name="line.1810"></a>
<span class="sourceLineNo">1811</span>    public boolean completePendingCommand() throws IOException<a name="line.1811"></a>
<span class="sourceLineNo">1812</span>    {<a name="line.1812"></a>
<span class="sourceLineNo">1813</span>        return FTPReply.isPositiveCompletion(getReply());<a name="line.1813"></a>
<span class="sourceLineNo">1814</span>    }<a name="line.1814"></a>
<span class="sourceLineNo">1815</span><a name="line.1815"></a>
<span class="sourceLineNo">1816</span><a name="line.1816"></a>
<span class="sourceLineNo">1817</span>    /**<a name="line.1817"></a>
<span class="sourceLineNo">1818</span>     * Retrieves a named file from the server and writes it to the given<a name="line.1818"></a>
<span class="sourceLineNo">1819</span>     * OutputStream.  This method does NOT close the given OutputStream.<a name="line.1819"></a>
<span class="sourceLineNo">1820</span>     * If the current file type is ASCII, line separators in the file are<a name="line.1820"></a>
<span class="sourceLineNo">1821</span>     * converted to the local representation.<a name="line.1821"></a>
<span class="sourceLineNo">1822</span>     * &lt;p&gt;<a name="line.1822"></a>
<span class="sourceLineNo">1823</span>     * Note: if you have used {@link #setRestartOffset(long)},<a name="line.1823"></a>
<span class="sourceLineNo">1824</span>     * the file data will start from the selected offset.<a name="line.1824"></a>
<span class="sourceLineNo">1825</span>     * @param remote  The name of the remote file.<a name="line.1825"></a>
<span class="sourceLineNo">1826</span>     * @param local   The local OutputStream to which to write the file.<a name="line.1826"></a>
<span class="sourceLineNo">1827</span>     * @return True if successfully completed, false if not.<a name="line.1827"></a>
<span class="sourceLineNo">1828</span>     * @exception FTPConnectionClosedException<a name="line.1828"></a>
<span class="sourceLineNo">1829</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1829"></a>
<span class="sourceLineNo">1830</span>     *      of the client being idle or some other reason causing the server<a name="line.1830"></a>
<span class="sourceLineNo">1831</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1831"></a>
<span class="sourceLineNo">1832</span>     *      as an IOException or independently as itself.<a name="line.1832"></a>
<span class="sourceLineNo">1833</span>     * @exception org.apache.commons.net.io.CopyStreamException<a name="line.1833"></a>
<span class="sourceLineNo">1834</span>     *      If an I/O error occurs while actually<a name="line.1834"></a>
<span class="sourceLineNo">1835</span>     *      transferring the file.  The CopyStreamException allows you to<a name="line.1835"></a>
<span class="sourceLineNo">1836</span>     *      determine the number of bytes transferred and the IOException<a name="line.1836"></a>
<span class="sourceLineNo">1837</span>     *      causing the error.  This exception may be caught either<a name="line.1837"></a>
<span class="sourceLineNo">1838</span>     *      as an IOException or independently as itself.<a name="line.1838"></a>
<span class="sourceLineNo">1839</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1839"></a>
<span class="sourceLineNo">1840</span>     *      command to the server or receiving a reply from the server.<a name="line.1840"></a>
<span class="sourceLineNo">1841</span>     */<a name="line.1841"></a>
<span class="sourceLineNo">1842</span>    public boolean retrieveFile(String remote, OutputStream local)<a name="line.1842"></a>
<span class="sourceLineNo">1843</span>    throws IOException<a name="line.1843"></a>
<span class="sourceLineNo">1844</span>    {<a name="line.1844"></a>
<span class="sourceLineNo">1845</span>        return _retrieveFile(FTPCmd.RETR.getCommand(), remote, local);<a name="line.1845"></a>
<span class="sourceLineNo">1846</span>    }<a name="line.1846"></a>
<span class="sourceLineNo">1847</span><a name="line.1847"></a>
<span class="sourceLineNo">1848</span>    /**<a name="line.1848"></a>
<span class="sourceLineNo">1849</span>     * @since 3.1<a name="line.1849"></a>
<span class="sourceLineNo">1850</span>     */<a name="line.1850"></a>
<span class="sourceLineNo">1851</span>    protected boolean _retrieveFile(String command, String remote, OutputStream local)<a name="line.1851"></a>
<span class="sourceLineNo">1852</span>    throws IOException<a name="line.1852"></a>
<span class="sourceLineNo">1853</span>    {<a name="line.1853"></a>
<span class="sourceLineNo">1854</span>        Socket socket = _openDataConnection_(command, remote);<a name="line.1854"></a>
<span class="sourceLineNo">1855</span><a name="line.1855"></a>
<span class="sourceLineNo">1856</span>        if (socket == null) {<a name="line.1856"></a>
<span class="sourceLineNo">1857</span>            return false;<a name="line.1857"></a>
<span class="sourceLineNo">1858</span>        }<a name="line.1858"></a>
<span class="sourceLineNo">1859</span><a name="line.1859"></a>
<span class="sourceLineNo">1860</span>        InputStream input = getBufferedInputStream(socket.getInputStream());<a name="line.1860"></a>
<span class="sourceLineNo">1861</span>        if (__fileType == ASCII_FILE_TYPE) {<a name="line.1861"></a>
<span class="sourceLineNo">1862</span>            input = new FromNetASCIIInputStream(input);<a name="line.1862"></a>
<span class="sourceLineNo">1863</span>        }<a name="line.1863"></a>
<span class="sourceLineNo">1864</span><a name="line.1864"></a>
<span class="sourceLineNo">1865</span>        CSL csl = null;<a name="line.1865"></a>
<span class="sourceLineNo">1866</span>        if (__controlKeepAliveTimeout &gt; 0) {<a name="line.1866"></a>
<span class="sourceLineNo">1867</span>            csl = new CSL(this, __controlKeepAliveTimeout, __controlKeepAliveReplyTimeout);<a name="line.1867"></a>
<span class="sourceLineNo">1868</span>        }<a name="line.1868"></a>
<span class="sourceLineNo">1869</span><a name="line.1869"></a>
<span class="sourceLineNo">1870</span>        // Treat everything else as binary for now<a name="line.1870"></a>
<span class="sourceLineNo">1871</span>        try<a name="line.1871"></a>
<span class="sourceLineNo">1872</span>        {<a name="line.1872"></a>
<span class="sourceLineNo">1873</span>            Util.copyStream(input, local, getBufferSize(),<a name="line.1873"></a>
<span class="sourceLineNo">1874</span>                    CopyStreamEvent.UNKNOWN_STREAM_SIZE, __mergeListeners(csl),<a name="line.1874"></a>
<span class="sourceLineNo">1875</span>                    false);<a name="line.1875"></a>
<span class="sourceLineNo">1876</span>        } finally {<a name="line.1876"></a>
<span class="sourceLineNo">1877</span>            Util.closeQuietly(input);<a name="line.1877"></a>
<span class="sourceLineNo">1878</span>            Util.closeQuietly(socket);<a name="line.1878"></a>
<span class="sourceLineNo">1879</span>            if (csl != null) {<a name="line.1879"></a>
<span class="sourceLineNo">1880</span>                csl.cleanUp(); // fetch any outstanding keepalive replies<a name="line.1880"></a>
<span class="sourceLineNo">1881</span>            }<a name="line.1881"></a>
<span class="sourceLineNo">1882</span>        }<a name="line.1882"></a>
<span class="sourceLineNo">1883</span><a name="line.1883"></a>
<span class="sourceLineNo">1884</span>        // Get the transfer response<a name="line.1884"></a>
<span class="sourceLineNo">1885</span>        boolean ok = completePendingCommand();<a name="line.1885"></a>
<span class="sourceLineNo">1886</span>        return ok;<a name="line.1886"></a>
<span class="sourceLineNo">1887</span>    }<a name="line.1887"></a>
<span class="sourceLineNo">1888</span><a name="line.1888"></a>
<span class="sourceLineNo">1889</span>    /**<a name="line.1889"></a>
<span class="sourceLineNo">1890</span>     * Returns an InputStream from which a named file from the server<a name="line.1890"></a>
<span class="sourceLineNo">1891</span>     * can be read.  If the current file type is ASCII, the returned<a name="line.1891"></a>
<span class="sourceLineNo">1892</span>     * InputStream will convert line separators in the file to<a name="line.1892"></a>
<span class="sourceLineNo">1893</span>     * the local representation.  You must close the InputStream when you<a name="line.1893"></a>
<span class="sourceLineNo">1894</span>     * finish reading from it.  The InputStream itself will take care of<a name="line.1894"></a>
<span class="sourceLineNo">1895</span>     * closing the parent data connection socket upon being closed.  To<a name="line.1895"></a>
<span class="sourceLineNo">1896</span>     * finalize the file transfer you must call<a name="line.1896"></a>
<span class="sourceLineNo">1897</span>     * {@link #completePendingCommand  completePendingCommand } and<a name="line.1897"></a>
<span class="sourceLineNo">1898</span>     * check its return value to verify success.<a name="line.1898"></a>
<span class="sourceLineNo">1899</span>     * &lt;p&gt;<a name="line.1899"></a>
<span class="sourceLineNo">1900</span>     * Note: if you have used {@link #setRestartOffset(long)},<a name="line.1900"></a>
<span class="sourceLineNo">1901</span>     * the file data will start from the selected offset.<a name="line.1901"></a>
<span class="sourceLineNo">1902</span>     *<a name="line.1902"></a>
<span class="sourceLineNo">1903</span>     * @param remote  The name of the remote file.<a name="line.1903"></a>
<span class="sourceLineNo">1904</span>     * @return An InputStream from which the remote file can be read.  If<a name="line.1904"></a>
<span class="sourceLineNo">1905</span>     *      the data connection cannot be opened (e.g., the file does not<a name="line.1905"></a>
<span class="sourceLineNo">1906</span>     *      exist), null is returned (in which case you may check the reply<a name="line.1906"></a>
<span class="sourceLineNo">1907</span>     *      code to determine the exact reason for failure).<a name="line.1907"></a>
<span class="sourceLineNo">1908</span>     * @exception FTPConnectionClosedException<a name="line.1908"></a>
<span class="sourceLineNo">1909</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1909"></a>
<span class="sourceLineNo">1910</span>     *      of the client being idle or some other reason causing the server<a name="line.1910"></a>
<span class="sourceLineNo">1911</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1911"></a>
<span class="sourceLineNo">1912</span>     *      as an IOException or independently as itself.<a name="line.1912"></a>
<span class="sourceLineNo">1913</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1913"></a>
<span class="sourceLineNo">1914</span>     *      command to the server or receiving a reply from the server.<a name="line.1914"></a>
<span class="sourceLineNo">1915</span>     */<a name="line.1915"></a>
<span class="sourceLineNo">1916</span>    public InputStream retrieveFileStream(String remote) throws IOException<a name="line.1916"></a>
<span class="sourceLineNo">1917</span>    {<a name="line.1917"></a>
<span class="sourceLineNo">1918</span>        return _retrieveFileStream(FTPCmd.RETR.getCommand(), remote);<a name="line.1918"></a>
<span class="sourceLineNo">1919</span>    }<a name="line.1919"></a>
<span class="sourceLineNo">1920</span><a name="line.1920"></a>
<span class="sourceLineNo">1921</span>    /**<a name="line.1921"></a>
<span class="sourceLineNo">1922</span>     * @since 3.1<a name="line.1922"></a>
<span class="sourceLineNo">1923</span>     */<a name="line.1923"></a>
<span class="sourceLineNo">1924</span>    protected InputStream _retrieveFileStream(String command, String remote)<a name="line.1924"></a>
<span class="sourceLineNo">1925</span>    throws IOException<a name="line.1925"></a>
<span class="sourceLineNo">1926</span>    {<a name="line.1926"></a>
<span class="sourceLineNo">1927</span>        Socket socket = _openDataConnection_(command, remote);<a name="line.1927"></a>
<span class="sourceLineNo">1928</span><a name="line.1928"></a>
<span class="sourceLineNo">1929</span>        if (socket == null) {<a name="line.1929"></a>
<span class="sourceLineNo">1930</span>            return null;<a name="line.1930"></a>
<span class="sourceLineNo">1931</span>        }<a name="line.1931"></a>
<span class="sourceLineNo">1932</span><a name="line.1932"></a>
<span class="sourceLineNo">1933</span>        InputStream input = socket.getInputStream();<a name="line.1933"></a>
<span class="sourceLineNo">1934</span>        if (__fileType == ASCII_FILE_TYPE) {<a name="line.1934"></a>
<span class="sourceLineNo">1935</span>            // We buffer ascii transfers because the buffering has to<a name="line.1935"></a>
<span class="sourceLineNo">1936</span>            // be interposed between FromNetASCIIOutputSream and the underlying<a name="line.1936"></a>
<span class="sourceLineNo">1937</span>            // socket input stream.  We don't buffer binary transfers<a name="line.1937"></a>
<span class="sourceLineNo">1938</span>            // because we don't want to impose a buffering policy on the<a name="line.1938"></a>
<span class="sourceLineNo">1939</span>            // programmer if possible.  Programmers can decide on their<a name="line.1939"></a>
<span class="sourceLineNo">1940</span>            // own if they want to wrap the SocketInputStream we return<a name="line.1940"></a>
<span class="sourceLineNo">1941</span>            // for file types other than ASCII.<a name="line.1941"></a>
<span class="sourceLineNo">1942</span>            input = getBufferedInputStream(input);<a name="line.1942"></a>
<span class="sourceLineNo">1943</span>            input = new FromNetASCIIInputStream(input);<a name="line.1943"></a>
<span class="sourceLineNo">1944</span>        }<a name="line.1944"></a>
<span class="sourceLineNo">1945</span>        return new org.apache.commons.net.io.SocketInputStream(socket, input);<a name="line.1945"></a>
<span class="sourceLineNo">1946</span>    }<a name="line.1946"></a>
<span class="sourceLineNo">1947</span><a name="line.1947"></a>
<span class="sourceLineNo">1948</span><a name="line.1948"></a>
<span class="sourceLineNo">1949</span>    /**<a name="line.1949"></a>
<span class="sourceLineNo">1950</span>     * Stores a file on the server using the given name and taking input<a name="line.1950"></a>
<span class="sourceLineNo">1951</span>     * from the given InputStream.  This method does NOT close the given<a name="line.1951"></a>
<span class="sourceLineNo">1952</span>     * InputStream.  If the current file type is ASCII, line separators in<a name="line.1952"></a>
<span class="sourceLineNo">1953</span>     * the file are transparently converted to the NETASCII format (i.e.,<a name="line.1953"></a>
<span class="sourceLineNo">1954</span>     * you should not attempt to create a special InputStream to do this).<a name="line.1954"></a>
<span class="sourceLineNo">1955</span>     * &lt;p&gt;<a name="line.1955"></a>
<span class="sourceLineNo">1956</span>     * @param remote  The name to give the remote file.<a name="line.1956"></a>
<span class="sourceLineNo">1957</span>     * @param local   The local InputStream from which to read the file.<a name="line.1957"></a>
<span class="sourceLineNo">1958</span>     * @return True if successfully completed, false if not.<a name="line.1958"></a>
<span class="sourceLineNo">1959</span>     * @exception FTPConnectionClosedException<a name="line.1959"></a>
<span class="sourceLineNo">1960</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1960"></a>
<span class="sourceLineNo">1961</span>     *      of the client being idle or some other reason causing the server<a name="line.1961"></a>
<span class="sourceLineNo">1962</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.1962"></a>
<span class="sourceLineNo">1963</span>     *      as an IOException or independently as itself.<a name="line.1963"></a>
<span class="sourceLineNo">1964</span>     * @exception org.apache.commons.net.io.CopyStreamException<a name="line.1964"></a>
<span class="sourceLineNo">1965</span>     *      If an I/O error occurs while actually<a name="line.1965"></a>
<span class="sourceLineNo">1966</span>     *      transferring the file.  The CopyStreamException allows you to<a name="line.1966"></a>
<span class="sourceLineNo">1967</span>     *      determine the number of bytes transferred and the IOException<a name="line.1967"></a>
<span class="sourceLineNo">1968</span>     *      causing the error.  This exception may be caught either<a name="line.1968"></a>
<span class="sourceLineNo">1969</span>     *      as an IOException or independently as itself.<a name="line.1969"></a>
<span class="sourceLineNo">1970</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.1970"></a>
<span class="sourceLineNo">1971</span>     *      command to the server or receiving a reply from the server.<a name="line.1971"></a>
<span class="sourceLineNo">1972</span>     */<a name="line.1972"></a>
<span class="sourceLineNo">1973</span>    public boolean storeFile(String remote, InputStream local)<a name="line.1973"></a>
<span class="sourceLineNo">1974</span>    throws IOException<a name="line.1974"></a>
<span class="sourceLineNo">1975</span>    {<a name="line.1975"></a>
<span class="sourceLineNo">1976</span>        return __storeFile(FTPCmd.STOR, remote, local);<a name="line.1976"></a>
<span class="sourceLineNo">1977</span>    }<a name="line.1977"></a>
<span class="sourceLineNo">1978</span><a name="line.1978"></a>
<span class="sourceLineNo">1979</span><a name="line.1979"></a>
<span class="sourceLineNo">1980</span>    /**<a name="line.1980"></a>
<span class="sourceLineNo">1981</span>     * Returns an OutputStream through which data can be written to store<a name="line.1981"></a>
<span class="sourceLineNo">1982</span>     * a file on the server using the given name.  If the current file type<a name="line.1982"></a>
<span class="sourceLineNo">1983</span>     * is ASCII, the returned OutputStream will convert line separators in<a name="line.1983"></a>
<span class="sourceLineNo">1984</span>     * the file to the NETASCII format  (i.e., you should not attempt to<a name="line.1984"></a>
<span class="sourceLineNo">1985</span>     * create a special OutputStream to do this).  You must close the<a name="line.1985"></a>
<span class="sourceLineNo">1986</span>     * OutputStream when you finish writing to it.  The OutputStream itself<a name="line.1986"></a>
<span class="sourceLineNo">1987</span>     * will take care of closing the parent data connection socket upon being<a name="line.1987"></a>
<span class="sourceLineNo">1988</span>     * closed.  To finalize the file transfer you must call<a name="line.1988"></a>
<span class="sourceLineNo">1989</span>     * {@link #completePendingCommand  completePendingCommand } and<a name="line.1989"></a>
<span class="sourceLineNo">1990</span>     * check its return value to verify success.<a name="line.1990"></a>
<span class="sourceLineNo">1991</span>     * &lt;p&gt;<a name="line.1991"></a>
<span class="sourceLineNo">1992</span>     * @param remote  The name to give the remote file.<a name="line.1992"></a>
<span class="sourceLineNo">1993</span>     * @return An OutputStream through which the remote file can be written.  If<a name="line.1993"></a>
<span class="sourceLineNo">1994</span>     *      the data connection cannot be opened (e.g., the file does not<a name="line.1994"></a>
<span class="sourceLineNo">1995</span>     *      exist), null is returned (in which case you may check the reply<a name="line.1995"></a>
<span class="sourceLineNo">1996</span>     *      code to determine the exact reason for failure).<a name="line.1996"></a>
<span class="sourceLineNo">1997</span>     * @exception FTPConnectionClosedException<a name="line.1997"></a>
<span class="sourceLineNo">1998</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.1998"></a>
<span class="sourceLineNo">1999</span>     *      of the client being idle or some other reason causing the server<a name="line.1999"></a>
<span class="sourceLineNo">2000</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2000"></a>
<span class="sourceLineNo">2001</span>     *      as an IOException or independently as itself.<a name="line.2001"></a>
<span class="sourceLineNo">2002</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2002"></a>
<span class="sourceLineNo">2003</span>     *      command to the server or receiving a reply from the server.<a name="line.2003"></a>
<span class="sourceLineNo">2004</span>     */<a name="line.2004"></a>
<span class="sourceLineNo">2005</span>    public OutputStream storeFileStream(String remote) throws IOException<a name="line.2005"></a>
<span class="sourceLineNo">2006</span>    {<a name="line.2006"></a>
<span class="sourceLineNo">2007</span>        return __storeFileStream(FTPCmd.STOR, remote);<a name="line.2007"></a>
<span class="sourceLineNo">2008</span>    }<a name="line.2008"></a>
<span class="sourceLineNo">2009</span><a name="line.2009"></a>
<span class="sourceLineNo">2010</span>    /**<a name="line.2010"></a>
<span class="sourceLineNo">2011</span>     * Appends to a file on the server with the given name, taking input<a name="line.2011"></a>
<span class="sourceLineNo">2012</span>     * from the given InputStream.  This method does NOT close the given<a name="line.2012"></a>
<span class="sourceLineNo">2013</span>     * InputStream.  If the current file type is ASCII, line separators in<a name="line.2013"></a>
<span class="sourceLineNo">2014</span>     * the file are transparently converted to the NETASCII format (i.e.,<a name="line.2014"></a>
<span class="sourceLineNo">2015</span>     * you should not attempt to create a special InputStream to do this).<a name="line.2015"></a>
<span class="sourceLineNo">2016</span>     * &lt;p&gt;<a name="line.2016"></a>
<span class="sourceLineNo">2017</span>     * @param remote  The name of the remote file.<a name="line.2017"></a>
<span class="sourceLineNo">2018</span>     * @param local   The local InputStream from which to read the data to<a name="line.2018"></a>
<span class="sourceLineNo">2019</span>     *                be appended to the remote file.<a name="line.2019"></a>
<span class="sourceLineNo">2020</span>     * @return True if successfully completed, false if not.<a name="line.2020"></a>
<span class="sourceLineNo">2021</span>     * @exception FTPConnectionClosedException<a name="line.2021"></a>
<span class="sourceLineNo">2022</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2022"></a>
<span class="sourceLineNo">2023</span>     *      of the client being idle or some other reason causing the server<a name="line.2023"></a>
<span class="sourceLineNo">2024</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2024"></a>
<span class="sourceLineNo">2025</span>     *      as an IOException or independently as itself.<a name="line.2025"></a>
<span class="sourceLineNo">2026</span>     * @exception org.apache.commons.net.io.CopyStreamException<a name="line.2026"></a>
<span class="sourceLineNo">2027</span>     *      If an I/O error occurs while actually<a name="line.2027"></a>
<span class="sourceLineNo">2028</span>     *      transferring the file.  The CopyStreamException allows you to<a name="line.2028"></a>
<span class="sourceLineNo">2029</span>     *      determine the number of bytes transferred and the IOException<a name="line.2029"></a>
<span class="sourceLineNo">2030</span>     *      causing the error.  This exception may be caught either<a name="line.2030"></a>
<span class="sourceLineNo">2031</span>     *      as an IOException or independently as itself.<a name="line.2031"></a>
<span class="sourceLineNo">2032</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2032"></a>
<span class="sourceLineNo">2033</span>     *      command to the server or receiving a reply from the server.<a name="line.2033"></a>
<span class="sourceLineNo">2034</span>     */<a name="line.2034"></a>
<span class="sourceLineNo">2035</span>    public boolean appendFile(String remote, InputStream local)<a name="line.2035"></a>
<span class="sourceLineNo">2036</span>    throws IOException<a name="line.2036"></a>
<span class="sourceLineNo">2037</span>    {<a name="line.2037"></a>
<span class="sourceLineNo">2038</span>        return __storeFile(FTPCmd.APPE, remote, local);<a name="line.2038"></a>
<span class="sourceLineNo">2039</span>    }<a name="line.2039"></a>
<span class="sourceLineNo">2040</span><a name="line.2040"></a>
<span class="sourceLineNo">2041</span>    /**<a name="line.2041"></a>
<span class="sourceLineNo">2042</span>     * Returns an OutputStream through which data can be written to append<a name="line.2042"></a>
<span class="sourceLineNo">2043</span>     * to a file on the server with the given name.  If the current file type<a name="line.2043"></a>
<span class="sourceLineNo">2044</span>     * is ASCII, the returned OutputStream will convert line separators in<a name="line.2044"></a>
<span class="sourceLineNo">2045</span>     * the file to the NETASCII format  (i.e., you should not attempt to<a name="line.2045"></a>
<span class="sourceLineNo">2046</span>     * create a special OutputStream to do this).  You must close the<a name="line.2046"></a>
<span class="sourceLineNo">2047</span>     * OutputStream when you finish writing to it.  The OutputStream itself<a name="line.2047"></a>
<span class="sourceLineNo">2048</span>     * will take care of closing the parent data connection socket upon being<a name="line.2048"></a>
<span class="sourceLineNo">2049</span>     * closed.  To finalize the file transfer you must call<a name="line.2049"></a>
<span class="sourceLineNo">2050</span>     * {@link #completePendingCommand  completePendingCommand } and<a name="line.2050"></a>
<span class="sourceLineNo">2051</span>     * check its return value to verify success.<a name="line.2051"></a>
<span class="sourceLineNo">2052</span>     * &lt;p&gt;<a name="line.2052"></a>
<span class="sourceLineNo">2053</span>     * @param remote  The name of the remote file.<a name="line.2053"></a>
<span class="sourceLineNo">2054</span>     * @return An OutputStream through which the remote file can be appended.<a name="line.2054"></a>
<span class="sourceLineNo">2055</span>     *      If the data connection cannot be opened (e.g., the file does not<a name="line.2055"></a>
<span class="sourceLineNo">2056</span>     *      exist), null is returned (in which case you may check the reply<a name="line.2056"></a>
<span class="sourceLineNo">2057</span>     *      code to determine the exact reason for failure).<a name="line.2057"></a>
<span class="sourceLineNo">2058</span>     * @exception FTPConnectionClosedException<a name="line.2058"></a>
<span class="sourceLineNo">2059</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2059"></a>
<span class="sourceLineNo">2060</span>     *      of the client being idle or some other reason causing the server<a name="line.2060"></a>
<span class="sourceLineNo">2061</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2061"></a>
<span class="sourceLineNo">2062</span>     *      as an IOException or independently as itself.<a name="line.2062"></a>
<span class="sourceLineNo">2063</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2063"></a>
<span class="sourceLineNo">2064</span>     *      command to the server or receiving a reply from the server.<a name="line.2064"></a>
<span class="sourceLineNo">2065</span>     */<a name="line.2065"></a>
<span class="sourceLineNo">2066</span>    public OutputStream appendFileStream(String remote) throws IOException<a name="line.2066"></a>
<span class="sourceLineNo">2067</span>    {<a name="line.2067"></a>
<span class="sourceLineNo">2068</span>        return __storeFileStream(FTPCmd.APPE, remote);<a name="line.2068"></a>
<span class="sourceLineNo">2069</span>    }<a name="line.2069"></a>
<span class="sourceLineNo">2070</span><a name="line.2070"></a>
<span class="sourceLineNo">2071</span>    /**<a name="line.2071"></a>
<span class="sourceLineNo">2072</span>     * Stores a file on the server using a unique name derived from the<a name="line.2072"></a>
<span class="sourceLineNo">2073</span>     * given name and taking input<a name="line.2073"></a>
<span class="sourceLineNo">2074</span>     * from the given InputStream.  This method does NOT close the given<a name="line.2074"></a>
<span class="sourceLineNo">2075</span>     * InputStream.  If the current file type is ASCII, line separators in<a name="line.2075"></a>
<span class="sourceLineNo">2076</span>     * the file are transparently converted to the NETASCII format (i.e.,<a name="line.2076"></a>
<span class="sourceLineNo">2077</span>     * you should not attempt to create a special InputStream to do this).<a name="line.2077"></a>
<span class="sourceLineNo">2078</span>     * &lt;p&gt;<a name="line.2078"></a>
<span class="sourceLineNo">2079</span>     * @param remote  The name on which to base the unique name given to<a name="line.2079"></a>
<span class="sourceLineNo">2080</span>     *                the remote file.<a name="line.2080"></a>
<span class="sourceLineNo">2081</span>     * @param local   The local InputStream from which to read the file.<a name="line.2081"></a>
<span class="sourceLineNo">2082</span>     * @return True if successfully completed, false if not.<a name="line.2082"></a>
<span class="sourceLineNo">2083</span>     * @exception FTPConnectionClosedException<a name="line.2083"></a>
<span class="sourceLineNo">2084</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2084"></a>
<span class="sourceLineNo">2085</span>     *      of the client being idle or some other reason causing the server<a name="line.2085"></a>
<span class="sourceLineNo">2086</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2086"></a>
<span class="sourceLineNo">2087</span>     *      as an IOException or independently as itself.<a name="line.2087"></a>
<span class="sourceLineNo">2088</span>     * @exception org.apache.commons.net.io.CopyStreamException<a name="line.2088"></a>
<span class="sourceLineNo">2089</span>     *      If an I/O error occurs while actually<a name="line.2089"></a>
<span class="sourceLineNo">2090</span>     *      transferring the file.  The CopyStreamException allows you to<a name="line.2090"></a>
<span class="sourceLineNo">2091</span>     *      determine the number of bytes transferred and the IOException<a name="line.2091"></a>
<span class="sourceLineNo">2092</span>     *      causing the error.  This exception may be caught either<a name="line.2092"></a>
<span class="sourceLineNo">2093</span>     *      as an IOException or independently as itself.<a name="line.2093"></a>
<span class="sourceLineNo">2094</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2094"></a>
<span class="sourceLineNo">2095</span>     *      command to the server or receiving a reply from the server.<a name="line.2095"></a>
<span class="sourceLineNo">2096</span>     */<a name="line.2096"></a>
<span class="sourceLineNo">2097</span>    public boolean storeUniqueFile(String remote, InputStream local)<a name="line.2097"></a>
<span class="sourceLineNo">2098</span>    throws IOException<a name="line.2098"></a>
<span class="sourceLineNo">2099</span>    {<a name="line.2099"></a>
<span class="sourceLineNo">2100</span>        return __storeFile(FTPCmd.STOU, remote, local);<a name="line.2100"></a>
<span class="sourceLineNo">2101</span>    }<a name="line.2101"></a>
<span class="sourceLineNo">2102</span><a name="line.2102"></a>
<span class="sourceLineNo">2103</span><a name="line.2103"></a>
<span class="sourceLineNo">2104</span>    /**<a name="line.2104"></a>
<span class="sourceLineNo">2105</span>     * Returns an OutputStream through which data can be written to store<a name="line.2105"></a>
<span class="sourceLineNo">2106</span>     * a file on the server using a unique name derived from the given name.<a name="line.2106"></a>
<span class="sourceLineNo">2107</span>     * If the current file type<a name="line.2107"></a>
<span class="sourceLineNo">2108</span>     * is ASCII, the returned OutputStream will convert line separators in<a name="line.2108"></a>
<span class="sourceLineNo">2109</span>     * the file to the NETASCII format  (i.e., you should not attempt to<a name="line.2109"></a>
<span class="sourceLineNo">2110</span>     * create a special OutputStream to do this).  You must close the<a name="line.2110"></a>
<span class="sourceLineNo">2111</span>     * OutputStream when you finish writing to it.  The OutputStream itself<a name="line.2111"></a>
<span class="sourceLineNo">2112</span>     * will take care of closing the parent data connection socket upon being<a name="line.2112"></a>
<span class="sourceLineNo">2113</span>     * closed.  To finalize the file transfer you must call<a name="line.2113"></a>
<span class="sourceLineNo">2114</span>     * {@link #completePendingCommand  completePendingCommand } and<a name="line.2114"></a>
<span class="sourceLineNo">2115</span>     * check its return value to verify success.<a name="line.2115"></a>
<span class="sourceLineNo">2116</span>     * &lt;p&gt;<a name="line.2116"></a>
<span class="sourceLineNo">2117</span>     * @param remote  The name on which to base the unique name given to<a name="line.2117"></a>
<span class="sourceLineNo">2118</span>     *                the remote file.<a name="line.2118"></a>
<span class="sourceLineNo">2119</span>     * @return An OutputStream through which the remote file can be written.  If<a name="line.2119"></a>
<span class="sourceLineNo">2120</span>     *      the data connection cannot be opened (e.g., the file does not<a name="line.2120"></a>
<span class="sourceLineNo">2121</span>     *      exist), null is returned (in which case you may check the reply<a name="line.2121"></a>
<span class="sourceLineNo">2122</span>     *      code to determine the exact reason for failure).<a name="line.2122"></a>
<span class="sourceLineNo">2123</span>     * @exception FTPConnectionClosedException<a name="line.2123"></a>
<span class="sourceLineNo">2124</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2124"></a>
<span class="sourceLineNo">2125</span>     *      of the client being idle or some other reason causing the server<a name="line.2125"></a>
<span class="sourceLineNo">2126</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2126"></a>
<span class="sourceLineNo">2127</span>     *      as an IOException or independently as itself.<a name="line.2127"></a>
<span class="sourceLineNo">2128</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2128"></a>
<span class="sourceLineNo">2129</span>     *      command to the server or receiving a reply from the server.<a name="line.2129"></a>
<span class="sourceLineNo">2130</span>     */<a name="line.2130"></a>
<span class="sourceLineNo">2131</span>    public OutputStream storeUniqueFileStream(String remote) throws IOException<a name="line.2131"></a>
<span class="sourceLineNo">2132</span>    {<a name="line.2132"></a>
<span class="sourceLineNo">2133</span>        return __storeFileStream(FTPCmd.STOU, remote);<a name="line.2133"></a>
<span class="sourceLineNo">2134</span>    }<a name="line.2134"></a>
<span class="sourceLineNo">2135</span><a name="line.2135"></a>
<span class="sourceLineNo">2136</span>    /**<a name="line.2136"></a>
<span class="sourceLineNo">2137</span>     * Stores a file on the server using a unique name assigned by the<a name="line.2137"></a>
<span class="sourceLineNo">2138</span>     * server and taking input from the given InputStream.  This method does<a name="line.2138"></a>
<span class="sourceLineNo">2139</span>     * NOT close the given<a name="line.2139"></a>
<span class="sourceLineNo">2140</span>     * InputStream.  If the current file type is ASCII, line separators in<a name="line.2140"></a>
<span class="sourceLineNo">2141</span>     * the file are transparently converted to the NETASCII format (i.e.,<a name="line.2141"></a>
<span class="sourceLineNo">2142</span>     * you should not attempt to create a special InputStream to do this).<a name="line.2142"></a>
<span class="sourceLineNo">2143</span>     * &lt;p&gt;<a name="line.2143"></a>
<span class="sourceLineNo">2144</span>     * @param local   The local InputStream from which to read the file.<a name="line.2144"></a>
<span class="sourceLineNo">2145</span>     * @return True if successfully completed, false if not.<a name="line.2145"></a>
<span class="sourceLineNo">2146</span>     * @exception FTPConnectionClosedException<a name="line.2146"></a>
<span class="sourceLineNo">2147</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2147"></a>
<span class="sourceLineNo">2148</span>     *      of the client being idle or some other reason causing the server<a name="line.2148"></a>
<span class="sourceLineNo">2149</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2149"></a>
<span class="sourceLineNo">2150</span>     *      as an IOException or independently as itself.<a name="line.2150"></a>
<span class="sourceLineNo">2151</span>     * @exception org.apache.commons.net.io.CopyStreamException<a name="line.2151"></a>
<span class="sourceLineNo">2152</span>     *      If an I/O error occurs while actually<a name="line.2152"></a>
<span class="sourceLineNo">2153</span>     *      transferring the file.  The CopyStreamException allows you to<a name="line.2153"></a>
<span class="sourceLineNo">2154</span>     *      determine the number of bytes transferred and the IOException<a name="line.2154"></a>
<span class="sourceLineNo">2155</span>     *      causing the error.  This exception may be caught either<a name="line.2155"></a>
<span class="sourceLineNo">2156</span>     *      as an IOException or independently as itself.<a name="line.2156"></a>
<span class="sourceLineNo">2157</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2157"></a>
<span class="sourceLineNo">2158</span>     *      command to the server or receiving a reply from the server.<a name="line.2158"></a>
<span class="sourceLineNo">2159</span>     */<a name="line.2159"></a>
<span class="sourceLineNo">2160</span>    public boolean storeUniqueFile(InputStream local) throws IOException<a name="line.2160"></a>
<span class="sourceLineNo">2161</span>    {<a name="line.2161"></a>
<span class="sourceLineNo">2162</span>        return __storeFile(FTPCmd.STOU, null, local);<a name="line.2162"></a>
<span class="sourceLineNo">2163</span>    }<a name="line.2163"></a>
<span class="sourceLineNo">2164</span><a name="line.2164"></a>
<span class="sourceLineNo">2165</span>    /**<a name="line.2165"></a>
<span class="sourceLineNo">2166</span>     * Returns an OutputStream through which data can be written to store<a name="line.2166"></a>
<span class="sourceLineNo">2167</span>     * a file on the server using a unique name assigned by the server.<a name="line.2167"></a>
<span class="sourceLineNo">2168</span>     * If the current file type<a name="line.2168"></a>
<span class="sourceLineNo">2169</span>     * is ASCII, the returned OutputStream will convert line separators in<a name="line.2169"></a>
<span class="sourceLineNo">2170</span>     * the file to the NETASCII format  (i.e., you should not attempt to<a name="line.2170"></a>
<span class="sourceLineNo">2171</span>     * create a special OutputStream to do this).  You must close the<a name="line.2171"></a>
<span class="sourceLineNo">2172</span>     * OutputStream when you finish writing to it.  The OutputStream itself<a name="line.2172"></a>
<span class="sourceLineNo">2173</span>     * will take care of closing the parent data connection socket upon being<a name="line.2173"></a>
<span class="sourceLineNo">2174</span>     * closed.  To finalize the file transfer you must call<a name="line.2174"></a>
<span class="sourceLineNo">2175</span>     * {@link #completePendingCommand  completePendingCommand } and<a name="line.2175"></a>
<span class="sourceLineNo">2176</span>     * check its return value to verify success.<a name="line.2176"></a>
<span class="sourceLineNo">2177</span>     * &lt;p&gt;<a name="line.2177"></a>
<span class="sourceLineNo">2178</span>     * @return An OutputStream through which the remote file can be written.  If<a name="line.2178"></a>
<span class="sourceLineNo">2179</span>     *      the data connection cannot be opened (e.g., the file does not<a name="line.2179"></a>
<span class="sourceLineNo">2180</span>     *      exist), null is returned (in which case you may check the reply<a name="line.2180"></a>
<span class="sourceLineNo">2181</span>     *      code to determine the exact reason for failure).<a name="line.2181"></a>
<span class="sourceLineNo">2182</span>     * @exception FTPConnectionClosedException<a name="line.2182"></a>
<span class="sourceLineNo">2183</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2183"></a>
<span class="sourceLineNo">2184</span>     *      of the client being idle or some other reason causing the server<a name="line.2184"></a>
<span class="sourceLineNo">2185</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2185"></a>
<span class="sourceLineNo">2186</span>     *      as an IOException or independently as itself.<a name="line.2186"></a>
<span class="sourceLineNo">2187</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2187"></a>
<span class="sourceLineNo">2188</span>     *      command to the server or receiving a reply from the server.<a name="line.2188"></a>
<span class="sourceLineNo">2189</span>     */<a name="line.2189"></a>
<span class="sourceLineNo">2190</span>    public OutputStream storeUniqueFileStream() throws IOException<a name="line.2190"></a>
<span class="sourceLineNo">2191</span>    {<a name="line.2191"></a>
<span class="sourceLineNo">2192</span>        return __storeFileStream(FTPCmd.STOU, null);<a name="line.2192"></a>
<span class="sourceLineNo">2193</span>    }<a name="line.2193"></a>
<span class="sourceLineNo">2194</span><a name="line.2194"></a>
<span class="sourceLineNo">2195</span>    /**<a name="line.2195"></a>
<span class="sourceLineNo">2196</span>     * Reserve a number of bytes on the server for the next file transfer.<a name="line.2196"></a>
<span class="sourceLineNo">2197</span>     * &lt;p&gt;<a name="line.2197"></a>
<span class="sourceLineNo">2198</span>     * @param bytes  The number of bytes which the server should allocate.<a name="line.2198"></a>
<span class="sourceLineNo">2199</span>     * @return True if successfully completed, false if not.<a name="line.2199"></a>
<span class="sourceLineNo">2200</span>     * @exception FTPConnectionClosedException<a name="line.2200"></a>
<span class="sourceLineNo">2201</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2201"></a>
<span class="sourceLineNo">2202</span>     *      of the client being idle or some other reason causing the server<a name="line.2202"></a>
<span class="sourceLineNo">2203</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2203"></a>
<span class="sourceLineNo">2204</span>     *      as an IOException or independently as itself.<a name="line.2204"></a>
<span class="sourceLineNo">2205</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2205"></a>
<span class="sourceLineNo">2206</span>     *      command to the server or receiving a reply from the server.<a name="line.2206"></a>
<span class="sourceLineNo">2207</span>     */<a name="line.2207"></a>
<span class="sourceLineNo">2208</span>    public boolean allocate(int bytes) throws IOException<a name="line.2208"></a>
<span class="sourceLineNo">2209</span>    {<a name="line.2209"></a>
<span class="sourceLineNo">2210</span>        return FTPReply.isPositiveCompletion(allo(bytes));<a name="line.2210"></a>
<span class="sourceLineNo">2211</span>    }<a name="line.2211"></a>
<span class="sourceLineNo">2212</span><a name="line.2212"></a>
<span class="sourceLineNo">2213</span>    /**<a name="line.2213"></a>
<span class="sourceLineNo">2214</span>     * Query the server for supported features. The server may reply with a list of server-supported exensions.<a name="line.2214"></a>
<span class="sourceLineNo">2215</span>     * For example, a typical client-server interaction might be (from RFC 2389):<a name="line.2215"></a>
<span class="sourceLineNo">2216</span>     * &lt;pre&gt;<a name="line.2216"></a>
<span class="sourceLineNo">2217</span>        C&gt; feat<a name="line.2217"></a>
<span class="sourceLineNo">2218</span>        S&gt; 211-Extensions supported:<a name="line.2218"></a>
<span class="sourceLineNo">2219</span>        S&gt;  MLST size*;create;modify*;perm;media-type<a name="line.2219"></a>
<span class="sourceLineNo">2220</span>        S&gt;  SIZE<a name="line.2220"></a>
<span class="sourceLineNo">2221</span>        S&gt;  COMPRESSION<a name="line.2221"></a>
<span class="sourceLineNo">2222</span>        S&gt;  MDTM<a name="line.2222"></a>
<span class="sourceLineNo">2223</span>        S&gt; 211 END<a name="line.2223"></a>
<span class="sourceLineNo">2224</span>     * &lt;/pre&gt;<a name="line.2224"></a>
<span class="sourceLineNo">2225</span>     * @see &lt;a href="http://www.faqs.org/rfcs/rfc2389.html"&gt;http://www.faqs.org/rfcs/rfc2389.html&lt;/a&gt;<a name="line.2225"></a>
<span class="sourceLineNo">2226</span>     * @return True if successfully completed, false if not.<a name="line.2226"></a>
<span class="sourceLineNo">2227</span>     * @throws IOException<a name="line.2227"></a>
<span class="sourceLineNo">2228</span>     * @since 2.2<a name="line.2228"></a>
<span class="sourceLineNo">2229</span>     */<a name="line.2229"></a>
<span class="sourceLineNo">2230</span>    public boolean features() throws IOException {<a name="line.2230"></a>
<span class="sourceLineNo">2231</span>        return FTPReply.isPositiveCompletion(feat());<a name="line.2231"></a>
<span class="sourceLineNo">2232</span>    }<a name="line.2232"></a>
<span class="sourceLineNo">2233</span><a name="line.2233"></a>
<span class="sourceLineNo">2234</span>    /**<a name="line.2234"></a>
<span class="sourceLineNo">2235</span>     * Query the server for a supported feature, and returns its values (if any).<a name="line.2235"></a>
<span class="sourceLineNo">2236</span>     * Caches the parsed response to avoid resending the command repeatedly.<a name="line.2236"></a>
<span class="sourceLineNo">2237</span>     *<a name="line.2237"></a>
<span class="sourceLineNo">2238</span>     * @return if the feature is present, returns the feature values (empty array if none)<a name="line.2238"></a>
<span class="sourceLineNo">2239</span>     * Returns {@code null} if the feature is not found or the command failed.<a name="line.2239"></a>
<span class="sourceLineNo">2240</span>     * Check {@link #getReplyCode()} or {@link #getReplyString()} if so.<a name="line.2240"></a>
<span class="sourceLineNo">2241</span>     * @throws IOException<a name="line.2241"></a>
<span class="sourceLineNo">2242</span>     * @since 3.0<a name="line.2242"></a>
<span class="sourceLineNo">2243</span>     */<a name="line.2243"></a>
<span class="sourceLineNo">2244</span>    public String[] featureValues(String feature) throws IOException {<a name="line.2244"></a>
<span class="sourceLineNo">2245</span>        if (!initFeatureMap()) {<a name="line.2245"></a>
<span class="sourceLineNo">2246</span>            return null;<a name="line.2246"></a>
<span class="sourceLineNo">2247</span>        }<a name="line.2247"></a>
<span class="sourceLineNo">2248</span>        Set&lt;String&gt; entries = __featuresMap.get(feature.toUpperCase(Locale.ENGLISH));<a name="line.2248"></a>
<span class="sourceLineNo">2249</span>        if (entries != null) {<a name="line.2249"></a>
<span class="sourceLineNo">2250</span>            return entries.toArray(new String[entries.size()]);<a name="line.2250"></a>
<span class="sourceLineNo">2251</span>        }<a name="line.2251"></a>
<span class="sourceLineNo">2252</span>        return null;<a name="line.2252"></a>
<span class="sourceLineNo">2253</span>    }<a name="line.2253"></a>
<span class="sourceLineNo">2254</span><a name="line.2254"></a>
<span class="sourceLineNo">2255</span>    /**<a name="line.2255"></a>
<span class="sourceLineNo">2256</span>     * Query the server for a supported feature, and returns the its value (if any).<a name="line.2256"></a>
<span class="sourceLineNo">2257</span>     * Caches the parsed response to avoid resending the command repeatedly.<a name="line.2257"></a>
<span class="sourceLineNo">2258</span>     *<a name="line.2258"></a>
<span class="sourceLineNo">2259</span>     * @return if the feature is present, returns the feature value or the empty string<a name="line.2259"></a>
<span class="sourceLineNo">2260</span>     * if the feature exists but has no value.<a name="line.2260"></a>
<span class="sourceLineNo">2261</span>     * Returns {@code null} if the feature is not found or the command failed.<a name="line.2261"></a>
<span class="sourceLineNo">2262</span>     * Check {@link #getReplyCode()} or {@link #getReplyString()} if so.<a name="line.2262"></a>
<span class="sourceLineNo">2263</span>     * @throws IOException<a name="line.2263"></a>
<span class="sourceLineNo">2264</span>     * @since 3.0<a name="line.2264"></a>
<span class="sourceLineNo">2265</span>     */<a name="line.2265"></a>
<span class="sourceLineNo">2266</span>    public String featureValue(String feature) throws IOException {<a name="line.2266"></a>
<span class="sourceLineNo">2267</span>        String [] values = featureValues(feature);<a name="line.2267"></a>
<span class="sourceLineNo">2268</span>        if (values != null) {<a name="line.2268"></a>
<span class="sourceLineNo">2269</span>            return values[0];<a name="line.2269"></a>
<span class="sourceLineNo">2270</span>        }<a name="line.2270"></a>
<span class="sourceLineNo">2271</span>        return null;<a name="line.2271"></a>
<span class="sourceLineNo">2272</span>    }<a name="line.2272"></a>
<span class="sourceLineNo">2273</span><a name="line.2273"></a>
<span class="sourceLineNo">2274</span>    /**<a name="line.2274"></a>
<span class="sourceLineNo">2275</span>     * Query the server for a supported feature.<a name="line.2275"></a>
<span class="sourceLineNo">2276</span>     * Caches the parsed response to avoid resending the command repeatedly.<a name="line.2276"></a>
<span class="sourceLineNo">2277</span>     *<a name="line.2277"></a>
<span class="sourceLineNo">2278</span>     * @param feature the name of the feature; it is converted to upper case.<a name="line.2278"></a>
<span class="sourceLineNo">2279</span>     * @return {@code true} if the feature is present, {@code false} if the feature is not present<a name="line.2279"></a>
<span class="sourceLineNo">2280</span>     * or the {@link #feat()} command failed. Check {@link #getReplyCode()} or {@link #getReplyString()}<a name="line.2280"></a>
<span class="sourceLineNo">2281</span>     * if it is necessary to distinguish these cases.<a name="line.2281"></a>
<span class="sourceLineNo">2282</span>     *<a name="line.2282"></a>
<span class="sourceLineNo">2283</span>     * @throws IOException<a name="line.2283"></a>
<span class="sourceLineNo">2284</span>     * @since 3.0<a name="line.2284"></a>
<span class="sourceLineNo">2285</span>     */<a name="line.2285"></a>
<span class="sourceLineNo">2286</span>    public boolean hasFeature(String feature) throws IOException {<a name="line.2286"></a>
<span class="sourceLineNo">2287</span>        if (!initFeatureMap()) {<a name="line.2287"></a>
<span class="sourceLineNo">2288</span>            return false;<a name="line.2288"></a>
<span class="sourceLineNo">2289</span>        }<a name="line.2289"></a>
<span class="sourceLineNo">2290</span>        return __featuresMap.containsKey(feature.toUpperCase(Locale.ENGLISH));<a name="line.2290"></a>
<span class="sourceLineNo">2291</span>    }<a name="line.2291"></a>
<span class="sourceLineNo">2292</span><a name="line.2292"></a>
<span class="sourceLineNo">2293</span>    /**<a name="line.2293"></a>
<span class="sourceLineNo">2294</span>     * Query the server for a supported feature with particular value,<a name="line.2294"></a>
<span class="sourceLineNo">2295</span>     * for example "AUTH SSL" or "AUTH TLS".<a name="line.2295"></a>
<span class="sourceLineNo">2296</span>     * Caches the parsed response to avoid resending the command repeatedly.<a name="line.2296"></a>
<span class="sourceLineNo">2297</span>     *<a name="line.2297"></a>
<span class="sourceLineNo">2298</span>     * @param feature the name of the feature; it is converted to upper case.<a name="line.2298"></a>
<span class="sourceLineNo">2299</span>     * @param value the value to find.<a name="line.2299"></a>
<span class="sourceLineNo">2300</span>     *<a name="line.2300"></a>
<span class="sourceLineNo">2301</span>     * @return {@code true} if the feature is present, {@code false} if the feature is not present<a name="line.2301"></a>
<span class="sourceLineNo">2302</span>     * or the {@link #feat()} command failed. Check {@link #getReplyCode()} or {@link #getReplyString()}<a name="line.2302"></a>
<span class="sourceLineNo">2303</span>     * if it is necessary to distinguish these cases.<a name="line.2303"></a>
<span class="sourceLineNo">2304</span>     *<a name="line.2304"></a>
<span class="sourceLineNo">2305</span>     * @throws IOException<a name="line.2305"></a>
<span class="sourceLineNo">2306</span>     * @since 3.0<a name="line.2306"></a>
<span class="sourceLineNo">2307</span>     */<a name="line.2307"></a>
<span class="sourceLineNo">2308</span>    public boolean hasFeature(String feature, String value) throws IOException {<a name="line.2308"></a>
<span class="sourceLineNo">2309</span>        if (!initFeatureMap()) {<a name="line.2309"></a>
<span class="sourceLineNo">2310</span>            return false;<a name="line.2310"></a>
<span class="sourceLineNo">2311</span>        }<a name="line.2311"></a>
<span class="sourceLineNo">2312</span>        Set&lt;String&gt; entries = __featuresMap.get(feature.toUpperCase(Locale.ENGLISH));<a name="line.2312"></a>
<span class="sourceLineNo">2313</span>        if (entries != null) {<a name="line.2313"></a>
<span class="sourceLineNo">2314</span>            return entries.contains(value);<a name="line.2314"></a>
<span class="sourceLineNo">2315</span>        }<a name="line.2315"></a>
<span class="sourceLineNo">2316</span>        return false;<a name="line.2316"></a>
<span class="sourceLineNo">2317</span>    }<a name="line.2317"></a>
<span class="sourceLineNo">2318</span><a name="line.2318"></a>
<span class="sourceLineNo">2319</span>    /*<a name="line.2319"></a>
<span class="sourceLineNo">2320</span>     * Create the feature map if not already created.<a name="line.2320"></a>
<span class="sourceLineNo">2321</span>     */<a name="line.2321"></a>
<span class="sourceLineNo">2322</span>    private boolean initFeatureMap() throws IOException {<a name="line.2322"></a>
<span class="sourceLineNo">2323</span>        if (__featuresMap == null) {<a name="line.2323"></a>
<span class="sourceLineNo">2324</span>            // Don't create map here, because next line may throw exception<a name="line.2324"></a>
<span class="sourceLineNo">2325</span>            boolean success = FTPReply.isPositiveCompletion(feat());<a name="line.2325"></a>
<span class="sourceLineNo">2326</span>            // we init the map here, so we don't keep trying if we know the command will fail<a name="line.2326"></a>
<span class="sourceLineNo">2327</span>            __featuresMap = new HashMap&lt;String, Set&lt;String&gt;&gt;();<a name="line.2327"></a>
<span class="sourceLineNo">2328</span>            if (!success) {<a name="line.2328"></a>
<span class="sourceLineNo">2329</span>                return false;<a name="line.2329"></a>
<span class="sourceLineNo">2330</span>            }<a name="line.2330"></a>
<span class="sourceLineNo">2331</span>            for (String l : getReplyStrings()) {<a name="line.2331"></a>
<span class="sourceLineNo">2332</span>                if (l.startsWith(" ")) { // it's a FEAT entry<a name="line.2332"></a>
<span class="sourceLineNo">2333</span>                    String key;<a name="line.2333"></a>
<span class="sourceLineNo">2334</span>                    String value="";<a name="line.2334"></a>
<span class="sourceLineNo">2335</span>                    int varsep = l.indexOf(' ', 1);<a name="line.2335"></a>
<span class="sourceLineNo">2336</span>                    if (varsep &gt; 0) {<a name="line.2336"></a>
<span class="sourceLineNo">2337</span>                        key = l.substring(1, varsep);<a name="line.2337"></a>
<span class="sourceLineNo">2338</span>                        value = l.substring(varsep+1);<a name="line.2338"></a>
<span class="sourceLineNo">2339</span>                    } else {<a name="line.2339"></a>
<span class="sourceLineNo">2340</span>                        key = l.substring(1);<a name="line.2340"></a>
<span class="sourceLineNo">2341</span>                    }<a name="line.2341"></a>
<span class="sourceLineNo">2342</span>                    key = key.toUpperCase(Locale.ENGLISH);<a name="line.2342"></a>
<span class="sourceLineNo">2343</span>                    Set&lt;String&gt; entries = __featuresMap.get(key);<a name="line.2343"></a>
<span class="sourceLineNo">2344</span>                    if (entries == null) {<a name="line.2344"></a>
<span class="sourceLineNo">2345</span>                        entries = new HashSet&lt;String&gt;();<a name="line.2345"></a>
<span class="sourceLineNo">2346</span>                        __featuresMap.put(key, entries);<a name="line.2346"></a>
<span class="sourceLineNo">2347</span>                    }<a name="line.2347"></a>
<span class="sourceLineNo">2348</span>                    entries.add(value);<a name="line.2348"></a>
<span class="sourceLineNo">2349</span>                }<a name="line.2349"></a>
<span class="sourceLineNo">2350</span>            }<a name="line.2350"></a>
<span class="sourceLineNo">2351</span>        }<a name="line.2351"></a>
<span class="sourceLineNo">2352</span>        return true;<a name="line.2352"></a>
<span class="sourceLineNo">2353</span>    }<a name="line.2353"></a>
<span class="sourceLineNo">2354</span><a name="line.2354"></a>
<span class="sourceLineNo">2355</span>    /**<a name="line.2355"></a>
<span class="sourceLineNo">2356</span>     * Reserve space on the server for the next file transfer.<a name="line.2356"></a>
<span class="sourceLineNo">2357</span>     * &lt;p&gt;<a name="line.2357"></a>
<span class="sourceLineNo">2358</span>     * @param bytes  The number of bytes which the server should allocate.<a name="line.2358"></a>
<span class="sourceLineNo">2359</span>     * @param recordSize  The size of a file record.<a name="line.2359"></a>
<span class="sourceLineNo">2360</span>     * @return True if successfully completed, false if not.<a name="line.2360"></a>
<span class="sourceLineNo">2361</span>     * @exception FTPConnectionClosedException<a name="line.2361"></a>
<span class="sourceLineNo">2362</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2362"></a>
<span class="sourceLineNo">2363</span>     *      of the client being idle or some other reason causing the server<a name="line.2363"></a>
<span class="sourceLineNo">2364</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2364"></a>
<span class="sourceLineNo">2365</span>     *      as an IOException or independently as itself.<a name="line.2365"></a>
<span class="sourceLineNo">2366</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2366"></a>
<span class="sourceLineNo">2367</span>     *      command to the server or receiving a reply from the server.<a name="line.2367"></a>
<span class="sourceLineNo">2368</span>     */<a name="line.2368"></a>
<span class="sourceLineNo">2369</span>    public boolean allocate(int bytes, int recordSize) throws IOException<a name="line.2369"></a>
<span class="sourceLineNo">2370</span>    {<a name="line.2370"></a>
<span class="sourceLineNo">2371</span>        return FTPReply.isPositiveCompletion(allo(bytes, recordSize));<a name="line.2371"></a>
<span class="sourceLineNo">2372</span>    }<a name="line.2372"></a>
<span class="sourceLineNo">2373</span><a name="line.2373"></a>
<span class="sourceLineNo">2374</span><a name="line.2374"></a>
<span class="sourceLineNo">2375</span>    /**<a name="line.2375"></a>
<span class="sourceLineNo">2376</span>     * Issue a command and wait for the reply.<a name="line.2376"></a>
<span class="sourceLineNo">2377</span>     * &lt;p&gt;<a name="line.2377"></a>
<span class="sourceLineNo">2378</span>     * Should only be used with commands that return replies on the<a name="line.2378"></a>
<span class="sourceLineNo">2379</span>     * command channel - do not use for LIST, NLST, MLSD etc.<a name="line.2379"></a>
<span class="sourceLineNo">2380</span>     * &lt;p&gt;<a name="line.2380"></a>
<span class="sourceLineNo">2381</span>     * @param command  The command to invoke<a name="line.2381"></a>
<span class="sourceLineNo">2382</span>     * @param params  The parameters string, may be {@code null}<a name="line.2382"></a>
<span class="sourceLineNo">2383</span>     * @return True if successfully completed, false if not, in which case<a name="line.2383"></a>
<span class="sourceLineNo">2384</span>     * call {@link #getReplyCode()} or {@link #getReplyString()}<a name="line.2384"></a>
<span class="sourceLineNo">2385</span>     * to get the reason.<a name="line.2385"></a>
<span class="sourceLineNo">2386</span>     *<a name="line.2386"></a>
<span class="sourceLineNo">2387</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2387"></a>
<span class="sourceLineNo">2388</span>     *      command to the server or receiving a reply from the server.<a name="line.2388"></a>
<span class="sourceLineNo">2389</span>     * @since 3.0<a name="line.2389"></a>
<span class="sourceLineNo">2390</span>     */<a name="line.2390"></a>
<span class="sourceLineNo">2391</span>    public boolean doCommand(String command, String params) throws IOException<a name="line.2391"></a>
<span class="sourceLineNo">2392</span>    {<a name="line.2392"></a>
<span class="sourceLineNo">2393</span>        return FTPReply.isPositiveCompletion(sendCommand(command, params));<a name="line.2393"></a>
<span class="sourceLineNo">2394</span>    }<a name="line.2394"></a>
<span class="sourceLineNo">2395</span><a name="line.2395"></a>
<span class="sourceLineNo">2396</span>    /**<a name="line.2396"></a>
<span class="sourceLineNo">2397</span>     * Issue a command and wait for the reply, returning it as an array of strings.<a name="line.2397"></a>
<span class="sourceLineNo">2398</span>     * &lt;p&gt;<a name="line.2398"></a>
<span class="sourceLineNo">2399</span>     * Should only be used with commands that return replies on the<a name="line.2399"></a>
<span class="sourceLineNo">2400</span>     * command channel - do not use for LIST, NLST, MLSD etc.<a name="line.2400"></a>
<span class="sourceLineNo">2401</span>     * &lt;p&gt;<a name="line.2401"></a>
<span class="sourceLineNo">2402</span>     * @param command  The command to invoke<a name="line.2402"></a>
<span class="sourceLineNo">2403</span>     * @param params  The parameters string, may be {@code null}<a name="line.2403"></a>
<span class="sourceLineNo">2404</span>     * @return The array of replies, or {@code null} if the command failed, in which case<a name="line.2404"></a>
<span class="sourceLineNo">2405</span>     * call {@link #getReplyCode()} or {@link #getReplyString()}<a name="line.2405"></a>
<span class="sourceLineNo">2406</span>     * to get the reason.<a name="line.2406"></a>
<span class="sourceLineNo">2407</span>     *<a name="line.2407"></a>
<span class="sourceLineNo">2408</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2408"></a>
<span class="sourceLineNo">2409</span>     *      command to the server or receiving a reply from the server.<a name="line.2409"></a>
<span class="sourceLineNo">2410</span>     * @since 3.0<a name="line.2410"></a>
<span class="sourceLineNo">2411</span>     */<a name="line.2411"></a>
<span class="sourceLineNo">2412</span>    public String[] doCommandAsStrings(String command, String params) throws IOException<a name="line.2412"></a>
<span class="sourceLineNo">2413</span>    {<a name="line.2413"></a>
<span class="sourceLineNo">2414</span>        boolean success = FTPReply.isPositiveCompletion(sendCommand(command, params));<a name="line.2414"></a>
<span class="sourceLineNo">2415</span>        if (success){<a name="line.2415"></a>
<span class="sourceLineNo">2416</span>            return getReplyStrings();<a name="line.2416"></a>
<span class="sourceLineNo">2417</span>        } else {<a name="line.2417"></a>
<span class="sourceLineNo">2418</span>            return null;<a name="line.2418"></a>
<span class="sourceLineNo">2419</span>        }<a name="line.2419"></a>
<span class="sourceLineNo">2420</span>    }<a name="line.2420"></a>
<span class="sourceLineNo">2421</span><a name="line.2421"></a>
<span class="sourceLineNo">2422</span>    /**<a name="line.2422"></a>
<span class="sourceLineNo">2423</span>     * Get file details using the MLST command<a name="line.2423"></a>
<span class="sourceLineNo">2424</span>     *<a name="line.2424"></a>
<span class="sourceLineNo">2425</span>     * @param pathname the file or directory to list, may be {@code} null<a name="line.2425"></a>
<span class="sourceLineNo">2426</span>     * @return the file details, may be {@code null}<a name="line.2426"></a>
<span class="sourceLineNo">2427</span>     * @throws IOException<a name="line.2427"></a>
<span class="sourceLineNo">2428</span>     * @since 3.0<a name="line.2428"></a>
<span class="sourceLineNo">2429</span>     */<a name="line.2429"></a>
<span class="sourceLineNo">2430</span>    public FTPFile mlistFile(String pathname) throws IOException<a name="line.2430"></a>
<span class="sourceLineNo">2431</span>    {<a name="line.2431"></a>
<span class="sourceLineNo">2432</span>        boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCmd.MLST, pathname));<a name="line.2432"></a>
<span class="sourceLineNo">2433</span>        if (success){<a name="line.2433"></a>
<span class="sourceLineNo">2434</span>            String entry = getReplyStrings()[1].substring(1); // skip leading space for parser<a name="line.2434"></a>
<span class="sourceLineNo">2435</span>            return MLSxEntryParser.parseEntry(entry);<a name="line.2435"></a>
<span class="sourceLineNo">2436</span>        } else {<a name="line.2436"></a>
<span class="sourceLineNo">2437</span>            return null;<a name="line.2437"></a>
<span class="sourceLineNo">2438</span>        }<a name="line.2438"></a>
<span class="sourceLineNo">2439</span>    }<a name="line.2439"></a>
<span class="sourceLineNo">2440</span><a name="line.2440"></a>
<span class="sourceLineNo">2441</span>    /**<a name="line.2441"></a>
<span class="sourceLineNo">2442</span>     * Generate a directory listing for the current directory using the MLSD command.<a name="line.2442"></a>
<span class="sourceLineNo">2443</span>     *<a name="line.2443"></a>
<span class="sourceLineNo">2444</span>     * @return the array of file entries<a name="line.2444"></a>
<span class="sourceLineNo">2445</span>     * @throws IOException<a name="line.2445"></a>
<span class="sourceLineNo">2446</span>     * @since 3.0<a name="line.2446"></a>
<span class="sourceLineNo">2447</span>     */<a name="line.2447"></a>
<span class="sourceLineNo">2448</span>    public FTPFile[] mlistDir() throws IOException<a name="line.2448"></a>
<span class="sourceLineNo">2449</span>    {<a name="line.2449"></a>
<span class="sourceLineNo">2450</span>        return mlistDir(null);<a name="line.2450"></a>
<span class="sourceLineNo">2451</span>    }<a name="line.2451"></a>
<span class="sourceLineNo">2452</span><a name="line.2452"></a>
<span class="sourceLineNo">2453</span>    /**<a name="line.2453"></a>
<span class="sourceLineNo">2454</span>     * Generate a directory listing using the MLSD command.<a name="line.2454"></a>
<span class="sourceLineNo">2455</span>     *<a name="line.2455"></a>
<span class="sourceLineNo">2456</span>     * @param pathname the directory name, may be {@code null}<a name="line.2456"></a>
<span class="sourceLineNo">2457</span>     * @return the array of file entries<a name="line.2457"></a>
<span class="sourceLineNo">2458</span>     * @throws IOException<a name="line.2458"></a>
<span class="sourceLineNo">2459</span>     * @since 3.0<a name="line.2459"></a>
<span class="sourceLineNo">2460</span>     */<a name="line.2460"></a>
<span class="sourceLineNo">2461</span>    public FTPFile[] mlistDir(String pathname) throws IOException<a name="line.2461"></a>
<span class="sourceLineNo">2462</span>    {<a name="line.2462"></a>
<span class="sourceLineNo">2463</span>        FTPListParseEngine engine = initiateMListParsing( pathname);<a name="line.2463"></a>
<span class="sourceLineNo">2464</span>        return engine.getFiles();<a name="line.2464"></a>
<span class="sourceLineNo">2465</span>    }<a name="line.2465"></a>
<span class="sourceLineNo">2466</span><a name="line.2466"></a>
<span class="sourceLineNo">2467</span>    /**<a name="line.2467"></a>
<span class="sourceLineNo">2468</span>     * Generate a directory listing using the MLSD command.<a name="line.2468"></a>
<span class="sourceLineNo">2469</span>     *<a name="line.2469"></a>
<span class="sourceLineNo">2470</span>     * @param pathname the directory name, may be {@code null}<a name="line.2470"></a>
<span class="sourceLineNo">2471</span>     * @param filter the filter to apply to the responses<a name="line.2471"></a>
<span class="sourceLineNo">2472</span>     * @return the array of file entries<a name="line.2472"></a>
<span class="sourceLineNo">2473</span>     * @throws IOException<a name="line.2473"></a>
<span class="sourceLineNo">2474</span>     * @since 3.0<a name="line.2474"></a>
<span class="sourceLineNo">2475</span>     */<a name="line.2475"></a>
<span class="sourceLineNo">2476</span>    public FTPFile[] mlistDir(String pathname, FTPFileFilter filter) throws IOException<a name="line.2476"></a>
<span class="sourceLineNo">2477</span>    {<a name="line.2477"></a>
<span class="sourceLineNo">2478</span>        FTPListParseEngine engine = initiateMListParsing( pathname);<a name="line.2478"></a>
<span class="sourceLineNo">2479</span>        return engine.getFiles(filter);<a name="line.2479"></a>
<span class="sourceLineNo">2480</span>    }<a name="line.2480"></a>
<span class="sourceLineNo">2481</span><a name="line.2481"></a>
<span class="sourceLineNo">2482</span>    /**<a name="line.2482"></a>
<span class="sourceLineNo">2483</span>     * Restart a &lt;code&gt;STREAM_TRANSFER_MODE&lt;/code&gt; file transfer starting<a name="line.2483"></a>
<span class="sourceLineNo">2484</span>     * from the given offset.  This will only work on FTP servers supporting<a name="line.2484"></a>
<span class="sourceLineNo">2485</span>     * the REST comand for the stream transfer mode.  However, most FTP<a name="line.2485"></a>
<span class="sourceLineNo">2486</span>     * servers support this.  Any subsequent file transfer will start<a name="line.2486"></a>
<span class="sourceLineNo">2487</span>     * reading or writing the remote file from the indicated offset.<a name="line.2487"></a>
<span class="sourceLineNo">2488</span>     * &lt;p&gt;<a name="line.2488"></a>
<span class="sourceLineNo">2489</span>     * @param offset  The offset into the remote file at which to start the<a name="line.2489"></a>
<span class="sourceLineNo">2490</span>     *           next file transfer.<a name="line.2490"></a>
<span class="sourceLineNo">2491</span>     * @return True if successfully completed, false if not.<a name="line.2491"></a>
<span class="sourceLineNo">2492</span>     * @exception FTPConnectionClosedException<a name="line.2492"></a>
<span class="sourceLineNo">2493</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2493"></a>
<span class="sourceLineNo">2494</span>     *      of the client being idle or some other reason causing the server<a name="line.2494"></a>
<span class="sourceLineNo">2495</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2495"></a>
<span class="sourceLineNo">2496</span>     *      as an IOException or independently as itself.<a name="line.2496"></a>
<span class="sourceLineNo">2497</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2497"></a>
<span class="sourceLineNo">2498</span>     *      command to the server or receiving a reply from the server.<a name="line.2498"></a>
<span class="sourceLineNo">2499</span>     * @since 3.1 (changed from private to protected)<a name="line.2499"></a>
<span class="sourceLineNo">2500</span>     */<a name="line.2500"></a>
<span class="sourceLineNo">2501</span>    protected boolean restart(long offset) throws IOException<a name="line.2501"></a>
<span class="sourceLineNo">2502</span>    {<a name="line.2502"></a>
<span class="sourceLineNo">2503</span>        __restartOffset = 0;<a name="line.2503"></a>
<span class="sourceLineNo">2504</span>        return FTPReply.isPositiveIntermediate(rest(Long.toString(offset)));<a name="line.2504"></a>
<span class="sourceLineNo">2505</span>    }<a name="line.2505"></a>
<span class="sourceLineNo">2506</span><a name="line.2506"></a>
<span class="sourceLineNo">2507</span>    /**<a name="line.2507"></a>
<span class="sourceLineNo">2508</span>     * Sets the restart offset for file transfers.<a name="line.2508"></a>
<span class="sourceLineNo">2509</span>     * &lt;p&gt;<a name="line.2509"></a>
<span class="sourceLineNo">2510</span>     * The restart command is not sent to the server immediately.<a name="line.2510"></a>
<span class="sourceLineNo">2511</span>     * It is sent when a data connection is created as part of a<a name="line.2511"></a>
<span class="sourceLineNo">2512</span>     * subsequent command.<a name="line.2512"></a>
<span class="sourceLineNo">2513</span>     * The restart marker is reset to zero after use.<a name="line.2513"></a>
<span class="sourceLineNo">2514</span>     * &lt;/p&gt;<a name="line.2514"></a>
<span class="sourceLineNo">2515</span>     * &lt;p&gt;<a name="line.2515"></a>
<span class="sourceLineNo">2516</span>     * &lt;b&gt;Note: This method should only be invoked immediately prior to<a name="line.2516"></a>
<span class="sourceLineNo">2517</span>     * the transfer to which it applies.&lt;/b&gt;<a name="line.2517"></a>
<span class="sourceLineNo">2518</span>     *<a name="line.2518"></a>
<span class="sourceLineNo">2519</span>     * @param offset  The offset into the remote file at which to start the<a name="line.2519"></a>
<span class="sourceLineNo">2520</span>     *           next file transfer.  This must be a value greater than or<a name="line.2520"></a>
<span class="sourceLineNo">2521</span>     *           equal to zero.<a name="line.2521"></a>
<span class="sourceLineNo">2522</span>     */<a name="line.2522"></a>
<span class="sourceLineNo">2523</span>    public void setRestartOffset(long offset)<a name="line.2523"></a>
<span class="sourceLineNo">2524</span>    {<a name="line.2524"></a>
<span class="sourceLineNo">2525</span>        if (offset &gt;= 0) {<a name="line.2525"></a>
<span class="sourceLineNo">2526</span>            __restartOffset = offset;<a name="line.2526"></a>
<span class="sourceLineNo">2527</span>        }<a name="line.2527"></a>
<span class="sourceLineNo">2528</span>    }<a name="line.2528"></a>
<span class="sourceLineNo">2529</span><a name="line.2529"></a>
<span class="sourceLineNo">2530</span>    /**<a name="line.2530"></a>
<span class="sourceLineNo">2531</span>     * Fetches the restart offset.<a name="line.2531"></a>
<span class="sourceLineNo">2532</span>     * &lt;p&gt;<a name="line.2532"></a>
<span class="sourceLineNo">2533</span>     * @return offset  The offset into the remote file at which to start the<a name="line.2533"></a>
<span class="sourceLineNo">2534</span>     *           next file transfer.<a name="line.2534"></a>
<span class="sourceLineNo">2535</span>     */<a name="line.2535"></a>
<span class="sourceLineNo">2536</span>    public long getRestartOffset()<a name="line.2536"></a>
<span class="sourceLineNo">2537</span>    {<a name="line.2537"></a>
<span class="sourceLineNo">2538</span>        return __restartOffset;<a name="line.2538"></a>
<span class="sourceLineNo">2539</span>    }<a name="line.2539"></a>
<span class="sourceLineNo">2540</span><a name="line.2540"></a>
<span class="sourceLineNo">2541</span><a name="line.2541"></a>
<span class="sourceLineNo">2542</span><a name="line.2542"></a>
<span class="sourceLineNo">2543</span>    /**<a name="line.2543"></a>
<span class="sourceLineNo">2544</span>     * Renames a remote file.<a name="line.2544"></a>
<span class="sourceLineNo">2545</span>     * &lt;p&gt;<a name="line.2545"></a>
<span class="sourceLineNo">2546</span>     * @param from  The name of the remote file to rename.<a name="line.2546"></a>
<span class="sourceLineNo">2547</span>     * @param to    The new name of the remote file.<a name="line.2547"></a>
<span class="sourceLineNo">2548</span>     * @return True if successfully completed, false if not.<a name="line.2548"></a>
<span class="sourceLineNo">2549</span>     * @exception FTPConnectionClosedException<a name="line.2549"></a>
<span class="sourceLineNo">2550</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2550"></a>
<span class="sourceLineNo">2551</span>     *      of the client being idle or some other reason causing the server<a name="line.2551"></a>
<span class="sourceLineNo">2552</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2552"></a>
<span class="sourceLineNo">2553</span>     *      as an IOException or independently as itself.<a name="line.2553"></a>
<span class="sourceLineNo">2554</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2554"></a>
<span class="sourceLineNo">2555</span>     *      command to the server or receiving a reply from the server.<a name="line.2555"></a>
<span class="sourceLineNo">2556</span>     */<a name="line.2556"></a>
<span class="sourceLineNo">2557</span>    public boolean rename(String from, String to) throws IOException<a name="line.2557"></a>
<span class="sourceLineNo">2558</span>    {<a name="line.2558"></a>
<span class="sourceLineNo">2559</span>        if (!FTPReply.isPositiveIntermediate(rnfr(from))) {<a name="line.2559"></a>
<span class="sourceLineNo">2560</span>            return false;<a name="line.2560"></a>
<span class="sourceLineNo">2561</span>        }<a name="line.2561"></a>
<span class="sourceLineNo">2562</span><a name="line.2562"></a>
<span class="sourceLineNo">2563</span>        return FTPReply.isPositiveCompletion(rnto(to));<a name="line.2563"></a>
<span class="sourceLineNo">2564</span>    }<a name="line.2564"></a>
<span class="sourceLineNo">2565</span><a name="line.2565"></a>
<span class="sourceLineNo">2566</span><a name="line.2566"></a>
<span class="sourceLineNo">2567</span>    /**<a name="line.2567"></a>
<span class="sourceLineNo">2568</span>     * Abort a transfer in progress.<a name="line.2568"></a>
<span class="sourceLineNo">2569</span>     * &lt;p&gt;<a name="line.2569"></a>
<span class="sourceLineNo">2570</span>     * @return True if successfully completed, false if not.<a name="line.2570"></a>
<span class="sourceLineNo">2571</span>     * @exception FTPConnectionClosedException<a name="line.2571"></a>
<span class="sourceLineNo">2572</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2572"></a>
<span class="sourceLineNo">2573</span>     *      of the client being idle or some other reason causing the server<a name="line.2573"></a>
<span class="sourceLineNo">2574</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2574"></a>
<span class="sourceLineNo">2575</span>     *      as an IOException or independently as itself.<a name="line.2575"></a>
<span class="sourceLineNo">2576</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2576"></a>
<span class="sourceLineNo">2577</span>     *      command to the server or receiving a reply from the server.<a name="line.2577"></a>
<span class="sourceLineNo">2578</span>     */<a name="line.2578"></a>
<span class="sourceLineNo">2579</span>    public boolean abort() throws IOException<a name="line.2579"></a>
<span class="sourceLineNo">2580</span>    {<a name="line.2580"></a>
<span class="sourceLineNo">2581</span>        return FTPReply.isPositiveCompletion(abor());<a name="line.2581"></a>
<span class="sourceLineNo">2582</span>    }<a name="line.2582"></a>
<span class="sourceLineNo">2583</span><a name="line.2583"></a>
<span class="sourceLineNo">2584</span>    /**<a name="line.2584"></a>
<span class="sourceLineNo">2585</span>     * Deletes a file on the FTP server.<a name="line.2585"></a>
<span class="sourceLineNo">2586</span>     * &lt;p&gt;<a name="line.2586"></a>
<span class="sourceLineNo">2587</span>     * @param pathname   The pathname of the file to be deleted.<a name="line.2587"></a>
<span class="sourceLineNo">2588</span>     * @return True if successfully completed, false if not.<a name="line.2588"></a>
<span class="sourceLineNo">2589</span>     * @exception FTPConnectionClosedException<a name="line.2589"></a>
<span class="sourceLineNo">2590</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2590"></a>
<span class="sourceLineNo">2591</span>     *      of the client being idle or some other reason causing the server<a name="line.2591"></a>
<span class="sourceLineNo">2592</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2592"></a>
<span class="sourceLineNo">2593</span>     *      as an IOException or independently as itself.<a name="line.2593"></a>
<span class="sourceLineNo">2594</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2594"></a>
<span class="sourceLineNo">2595</span>     *      command to the server or receiving a reply from the server.<a name="line.2595"></a>
<span class="sourceLineNo">2596</span>     */<a name="line.2596"></a>
<span class="sourceLineNo">2597</span>    public boolean deleteFile(String pathname) throws IOException<a name="line.2597"></a>
<span class="sourceLineNo">2598</span>    {<a name="line.2598"></a>
<span class="sourceLineNo">2599</span>        return FTPReply.isPositiveCompletion(dele(pathname));<a name="line.2599"></a>
<span class="sourceLineNo">2600</span>    }<a name="line.2600"></a>
<span class="sourceLineNo">2601</span><a name="line.2601"></a>
<span class="sourceLineNo">2602</span><a name="line.2602"></a>
<span class="sourceLineNo">2603</span>    /**<a name="line.2603"></a>
<span class="sourceLineNo">2604</span>     * Removes a directory on the FTP server (if empty).<a name="line.2604"></a>
<span class="sourceLineNo">2605</span>     * &lt;p&gt;<a name="line.2605"></a>
<span class="sourceLineNo">2606</span>     * @param pathname  The pathname of the directory to remove.<a name="line.2606"></a>
<span class="sourceLineNo">2607</span>     * @return True if successfully completed, false if not.<a name="line.2607"></a>
<span class="sourceLineNo">2608</span>     * @exception FTPConnectionClosedException<a name="line.2608"></a>
<span class="sourceLineNo">2609</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2609"></a>
<span class="sourceLineNo">2610</span>     *      of the client being idle or some other reason causing the server<a name="line.2610"></a>
<span class="sourceLineNo">2611</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2611"></a>
<span class="sourceLineNo">2612</span>     *      as an IOException or independently as itself.<a name="line.2612"></a>
<span class="sourceLineNo">2613</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2613"></a>
<span class="sourceLineNo">2614</span>     *      command to the server or receiving a reply from the server.<a name="line.2614"></a>
<span class="sourceLineNo">2615</span>     */<a name="line.2615"></a>
<span class="sourceLineNo">2616</span>    public boolean removeDirectory(String pathname) throws IOException<a name="line.2616"></a>
<span class="sourceLineNo">2617</span>    {<a name="line.2617"></a>
<span class="sourceLineNo">2618</span>        return FTPReply.isPositiveCompletion(rmd(pathname));<a name="line.2618"></a>
<span class="sourceLineNo">2619</span>    }<a name="line.2619"></a>
<span class="sourceLineNo">2620</span><a name="line.2620"></a>
<span class="sourceLineNo">2621</span><a name="line.2621"></a>
<span class="sourceLineNo">2622</span>    /**<a name="line.2622"></a>
<span class="sourceLineNo">2623</span>     * Creates a new subdirectory on the FTP server in the current directory<a name="line.2623"></a>
<span class="sourceLineNo">2624</span>     * (if a relative pathname is given) or where specified (if an absolute<a name="line.2624"></a>
<span class="sourceLineNo">2625</span>     * pathname is given).<a name="line.2625"></a>
<span class="sourceLineNo">2626</span>     * &lt;p&gt;<a name="line.2626"></a>
<span class="sourceLineNo">2627</span>     * @param pathname The pathname of the directory to create.<a name="line.2627"></a>
<span class="sourceLineNo">2628</span>     * @return True if successfully completed, false if not.<a name="line.2628"></a>
<span class="sourceLineNo">2629</span>     * @exception FTPConnectionClosedException<a name="line.2629"></a>
<span class="sourceLineNo">2630</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2630"></a>
<span class="sourceLineNo">2631</span>     *      of the client being idle or some other reason causing the server<a name="line.2631"></a>
<span class="sourceLineNo">2632</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2632"></a>
<span class="sourceLineNo">2633</span>     *      as an IOException or independently as itself.<a name="line.2633"></a>
<span class="sourceLineNo">2634</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2634"></a>
<span class="sourceLineNo">2635</span>     *      command to the server or receiving a reply from the server.<a name="line.2635"></a>
<span class="sourceLineNo">2636</span>     */<a name="line.2636"></a>
<span class="sourceLineNo">2637</span>    public boolean makeDirectory(String pathname) throws IOException<a name="line.2637"></a>
<span class="sourceLineNo">2638</span>    {<a name="line.2638"></a>
<span class="sourceLineNo">2639</span>        return FTPReply.isPositiveCompletion(mkd(pathname));<a name="line.2639"></a>
<span class="sourceLineNo">2640</span>    }<a name="line.2640"></a>
<span class="sourceLineNo">2641</span><a name="line.2641"></a>
<span class="sourceLineNo">2642</span><a name="line.2642"></a>
<span class="sourceLineNo">2643</span>    /**<a name="line.2643"></a>
<span class="sourceLineNo">2644</span>     * Returns the pathname of the current working directory.<a name="line.2644"></a>
<span class="sourceLineNo">2645</span>     * &lt;p&gt;<a name="line.2645"></a>
<span class="sourceLineNo">2646</span>     * @return The pathname of the current working directory.  If it cannot<a name="line.2646"></a>
<span class="sourceLineNo">2647</span>     *         be obtained, returns null.<a name="line.2647"></a>
<span class="sourceLineNo">2648</span>     * @exception FTPConnectionClosedException<a name="line.2648"></a>
<span class="sourceLineNo">2649</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2649"></a>
<span class="sourceLineNo">2650</span>     *      of the client being idle or some other reason causing the server<a name="line.2650"></a>
<span class="sourceLineNo">2651</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2651"></a>
<span class="sourceLineNo">2652</span>     *      as an IOException or independently as itself.<a name="line.2652"></a>
<span class="sourceLineNo">2653</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2653"></a>
<span class="sourceLineNo">2654</span>     *      command to the server or receiving a reply from the server.<a name="line.2654"></a>
<span class="sourceLineNo">2655</span>     */<a name="line.2655"></a>
<span class="sourceLineNo">2656</span>    public String printWorkingDirectory() throws IOException<a name="line.2656"></a>
<span class="sourceLineNo">2657</span>    {<a name="line.2657"></a>
<span class="sourceLineNo">2658</span>        if (pwd() != FTPReply.PATHNAME_CREATED) {<a name="line.2658"></a>
<span class="sourceLineNo">2659</span>            return null;<a name="line.2659"></a>
<span class="sourceLineNo">2660</span>        }<a name="line.2660"></a>
<span class="sourceLineNo">2661</span><a name="line.2661"></a>
<span class="sourceLineNo">2662</span>        return __parsePathname(_replyLines.get( _replyLines.size() - 1));<a name="line.2662"></a>
<span class="sourceLineNo">2663</span>    }<a name="line.2663"></a>
<span class="sourceLineNo">2664</span><a name="line.2664"></a>
<span class="sourceLineNo">2665</span><a name="line.2665"></a>
<span class="sourceLineNo">2666</span>    /**<a name="line.2666"></a>
<span class="sourceLineNo">2667</span>     * Send a site specific command.<a name="line.2667"></a>
<span class="sourceLineNo">2668</span>     * @param arguments The site specific command and arguments.<a name="line.2668"></a>
<span class="sourceLineNo">2669</span>     * @return True if successfully completed, false if not.<a name="line.2669"></a>
<span class="sourceLineNo">2670</span>     * @exception FTPConnectionClosedException<a name="line.2670"></a>
<span class="sourceLineNo">2671</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2671"></a>
<span class="sourceLineNo">2672</span>     *      of the client being idle or some other reason causing the server<a name="line.2672"></a>
<span class="sourceLineNo">2673</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2673"></a>
<span class="sourceLineNo">2674</span>     *      as an IOException or independently as itself.<a name="line.2674"></a>
<span class="sourceLineNo">2675</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2675"></a>
<span class="sourceLineNo">2676</span>     *      command to the server or receiving a reply from the server.<a name="line.2676"></a>
<span class="sourceLineNo">2677</span>     */<a name="line.2677"></a>
<span class="sourceLineNo">2678</span>    public boolean sendSiteCommand(String arguments) throws IOException<a name="line.2678"></a>
<span class="sourceLineNo">2679</span>    {<a name="line.2679"></a>
<span class="sourceLineNo">2680</span>        return FTPReply.isPositiveCompletion(site(arguments));<a name="line.2680"></a>
<span class="sourceLineNo">2681</span>    }<a name="line.2681"></a>
<span class="sourceLineNo">2682</span><a name="line.2682"></a>
<span class="sourceLineNo">2683</span><a name="line.2683"></a>
<span class="sourceLineNo">2684</span>    /**<a name="line.2684"></a>
<span class="sourceLineNo">2685</span>     * Fetches the system type from the server and returns the string.<a name="line.2685"></a>
<span class="sourceLineNo">2686</span>     * This value is cached for the duration of the connection after the<a name="line.2686"></a>
<span class="sourceLineNo">2687</span>     * first call to this method.  In other words, only the first time<a name="line.2687"></a>
<span class="sourceLineNo">2688</span>     * that you invoke this method will it issue a SYST command to the<a name="line.2688"></a>
<span class="sourceLineNo">2689</span>     * FTP server.  FTPClient will remember the value and return the<a name="line.2689"></a>
<span class="sourceLineNo">2690</span>     * cached value until a call to disconnect.<a name="line.2690"></a>
<span class="sourceLineNo">2691</span>     * &lt;p&gt;<a name="line.2691"></a>
<span class="sourceLineNo">2692</span>     * If the SYST command fails, and the system property<a name="line.2692"></a>
<span class="sourceLineNo">2693</span>     * {@link #FTP_SYSTEM_TYPE_DEFAULT} is defined, then this is used instead.<a name="line.2693"></a>
<span class="sourceLineNo">2694</span>     * @return The system type obtained from the server. Never null.<a name="line.2694"></a>
<span class="sourceLineNo">2695</span>     * @exception FTPConnectionClosedException<a name="line.2695"></a>
<span class="sourceLineNo">2696</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2696"></a>
<span class="sourceLineNo">2697</span>     *      of the client being idle or some other reason causing the server<a name="line.2697"></a>
<span class="sourceLineNo">2698</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2698"></a>
<span class="sourceLineNo">2699</span>     *      as an IOException or independently as itself.<a name="line.2699"></a>
<span class="sourceLineNo">2700</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2700"></a>
<span class="sourceLineNo">2701</span>     *  command to the server or receiving a reply from the server (and the default<a name="line.2701"></a>
<span class="sourceLineNo">2702</span>     *  system type property is not defined)<a name="line.2702"></a>
<span class="sourceLineNo">2703</span>     *  @since 2.2<a name="line.2703"></a>
<span class="sourceLineNo">2704</span>     */<a name="line.2704"></a>
<span class="sourceLineNo">2705</span>    public String getSystemType() throws IOException<a name="line.2705"></a>
<span class="sourceLineNo">2706</span>    {<a name="line.2706"></a>
<span class="sourceLineNo">2707</span>        //if (syst() == FTPReply.NAME_SYSTEM_TYPE)<a name="line.2707"></a>
<span class="sourceLineNo">2708</span>        // Technically, we should expect a NAME_SYSTEM_TYPE response, but<a name="line.2708"></a>
<span class="sourceLineNo">2709</span>        // in practice FTP servers deviate, so we soften the condition to<a name="line.2709"></a>
<span class="sourceLineNo">2710</span>        // a positive completion.<a name="line.2710"></a>
<span class="sourceLineNo">2711</span>        if (__systemName == null){<a name="line.2711"></a>
<span class="sourceLineNo">2712</span>            if (FTPReply.isPositiveCompletion(syst())) {<a name="line.2712"></a>
<span class="sourceLineNo">2713</span>                // Assume that response is not empty here (cannot be null)<a name="line.2713"></a>
<span class="sourceLineNo">2714</span>                __systemName = _replyLines.get(_replyLines.size() - 1).substring(4);<a name="line.2714"></a>
<span class="sourceLineNo">2715</span>            } else {<a name="line.2715"></a>
<span class="sourceLineNo">2716</span>                // Check if the user has provided a default for when the SYST command fails<a name="line.2716"></a>
<span class="sourceLineNo">2717</span>                String systDefault = System.getProperty(FTP_SYSTEM_TYPE_DEFAULT);<a name="line.2717"></a>
<span class="sourceLineNo">2718</span>                if (systDefault != null) {<a name="line.2718"></a>
<span class="sourceLineNo">2719</span>                    __systemName = systDefault;<a name="line.2719"></a>
<span class="sourceLineNo">2720</span>                } else {<a name="line.2720"></a>
<span class="sourceLineNo">2721</span>                    throw new IOException("Unable to determine system type - response: " + getReplyString());<a name="line.2721"></a>
<span class="sourceLineNo">2722</span>                }<a name="line.2722"></a>
<span class="sourceLineNo">2723</span>            }<a name="line.2723"></a>
<span class="sourceLineNo">2724</span>        }<a name="line.2724"></a>
<span class="sourceLineNo">2725</span>        return __systemName;<a name="line.2725"></a>
<span class="sourceLineNo">2726</span>    }<a name="line.2726"></a>
<span class="sourceLineNo">2727</span><a name="line.2727"></a>
<span class="sourceLineNo">2728</span><a name="line.2728"></a>
<span class="sourceLineNo">2729</span>    /**<a name="line.2729"></a>
<span class="sourceLineNo">2730</span>     * Fetches the system help information from the server and returns the<a name="line.2730"></a>
<span class="sourceLineNo">2731</span>     * full string.<a name="line.2731"></a>
<span class="sourceLineNo">2732</span>     * &lt;p&gt;<a name="line.2732"></a>
<span class="sourceLineNo">2733</span>     * @return The system help string obtained from the server.  null if the<a name="line.2733"></a>
<span class="sourceLineNo">2734</span>     *       information could not be obtained.<a name="line.2734"></a>
<span class="sourceLineNo">2735</span>     * @exception FTPConnectionClosedException<a name="line.2735"></a>
<span class="sourceLineNo">2736</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2736"></a>
<span class="sourceLineNo">2737</span>     *      of the client being idle or some other reason causing the server<a name="line.2737"></a>
<span class="sourceLineNo">2738</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2738"></a>
<span class="sourceLineNo">2739</span>     *      as an IOException or independently as itself.<a name="line.2739"></a>
<span class="sourceLineNo">2740</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2740"></a>
<span class="sourceLineNo">2741</span>     *  command to the server or receiving a reply from the server.<a name="line.2741"></a>
<span class="sourceLineNo">2742</span>     */<a name="line.2742"></a>
<span class="sourceLineNo">2743</span>    public String listHelp() throws IOException<a name="line.2743"></a>
<span class="sourceLineNo">2744</span>    {<a name="line.2744"></a>
<span class="sourceLineNo">2745</span>        if (FTPReply.isPositiveCompletion(help())) {<a name="line.2745"></a>
<span class="sourceLineNo">2746</span>            return getReplyString();<a name="line.2746"></a>
<span class="sourceLineNo">2747</span>        }<a name="line.2747"></a>
<span class="sourceLineNo">2748</span>        return null;<a name="line.2748"></a>
<span class="sourceLineNo">2749</span>    }<a name="line.2749"></a>
<span class="sourceLineNo">2750</span><a name="line.2750"></a>
<span class="sourceLineNo">2751</span><a name="line.2751"></a>
<span class="sourceLineNo">2752</span>    /**<a name="line.2752"></a>
<span class="sourceLineNo">2753</span>     * Fetches the help information for a given command from the server and<a name="line.2753"></a>
<span class="sourceLineNo">2754</span>     * returns the full string.<a name="line.2754"></a>
<span class="sourceLineNo">2755</span>     * @param command The command on which to ask for help.<a name="line.2755"></a>
<span class="sourceLineNo">2756</span>     * @return The command help string obtained from the server.  null if the<a name="line.2756"></a>
<span class="sourceLineNo">2757</span>     *       information could not be obtained.<a name="line.2757"></a>
<span class="sourceLineNo">2758</span>     * @exception FTPConnectionClosedException<a name="line.2758"></a>
<span class="sourceLineNo">2759</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2759"></a>
<span class="sourceLineNo">2760</span>     *      of the client being idle or some other reason causing the server<a name="line.2760"></a>
<span class="sourceLineNo">2761</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2761"></a>
<span class="sourceLineNo">2762</span>     *      as an IOException or independently as itself.<a name="line.2762"></a>
<span class="sourceLineNo">2763</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2763"></a>
<span class="sourceLineNo">2764</span>     *  command to the server or receiving a reply from the server.<a name="line.2764"></a>
<span class="sourceLineNo">2765</span>     */<a name="line.2765"></a>
<span class="sourceLineNo">2766</span>    public String listHelp(String command) throws IOException<a name="line.2766"></a>
<span class="sourceLineNo">2767</span>    {<a name="line.2767"></a>
<span class="sourceLineNo">2768</span>        if (FTPReply.isPositiveCompletion(help(command))) {<a name="line.2768"></a>
<span class="sourceLineNo">2769</span>            return getReplyString();<a name="line.2769"></a>
<span class="sourceLineNo">2770</span>        }<a name="line.2770"></a>
<span class="sourceLineNo">2771</span>        return null;<a name="line.2771"></a>
<span class="sourceLineNo">2772</span>    }<a name="line.2772"></a>
<span class="sourceLineNo">2773</span><a name="line.2773"></a>
<span class="sourceLineNo">2774</span><a name="line.2774"></a>
<span class="sourceLineNo">2775</span>    /**<a name="line.2775"></a>
<span class="sourceLineNo">2776</span>     * Sends a NOOP command to the FTP server.  This is useful for preventing<a name="line.2776"></a>
<span class="sourceLineNo">2777</span>     * server timeouts.<a name="line.2777"></a>
<span class="sourceLineNo">2778</span>     * &lt;p&gt;<a name="line.2778"></a>
<span class="sourceLineNo">2779</span>     * @return True if successfully completed, false if not.<a name="line.2779"></a>
<span class="sourceLineNo">2780</span>     * @exception FTPConnectionClosedException<a name="line.2780"></a>
<span class="sourceLineNo">2781</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2781"></a>
<span class="sourceLineNo">2782</span>     *      of the client being idle or some other reason causing the server<a name="line.2782"></a>
<span class="sourceLineNo">2783</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2783"></a>
<span class="sourceLineNo">2784</span>     *      as an IOException or independently as itself.<a name="line.2784"></a>
<span class="sourceLineNo">2785</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2785"></a>
<span class="sourceLineNo">2786</span>     *      command to the server or receiving a reply from the server.<a name="line.2786"></a>
<span class="sourceLineNo">2787</span>     */<a name="line.2787"></a>
<span class="sourceLineNo">2788</span>    public boolean sendNoOp() throws IOException<a name="line.2788"></a>
<span class="sourceLineNo">2789</span>    {<a name="line.2789"></a>
<span class="sourceLineNo">2790</span>        return FTPReply.isPositiveCompletion(noop());<a name="line.2790"></a>
<span class="sourceLineNo">2791</span>    }<a name="line.2791"></a>
<span class="sourceLineNo">2792</span><a name="line.2792"></a>
<span class="sourceLineNo">2793</span><a name="line.2793"></a>
<span class="sourceLineNo">2794</span>    /**<a name="line.2794"></a>
<span class="sourceLineNo">2795</span>     * Obtain a list of filenames in a directory (or just the name of a given<a name="line.2795"></a>
<span class="sourceLineNo">2796</span>     * file, which is not particularly useful).  This information is obtained<a name="line.2796"></a>
<span class="sourceLineNo">2797</span>     * through the NLST command.  If the given pathname is a directory and<a name="line.2797"></a>
<span class="sourceLineNo">2798</span>     * contains no files,  a zero length array is returned only<a name="line.2798"></a>
<span class="sourceLineNo">2799</span>     * if the FTP server returned a positive completion code, otherwise<a name="line.2799"></a>
<span class="sourceLineNo">2800</span>     * null is returned (the FTP server returned a 550 error No files found.).<a name="line.2800"></a>
<span class="sourceLineNo">2801</span>     * If the directory is not empty, an array of filenames in the directory is<a name="line.2801"></a>
<span class="sourceLineNo">2802</span>     * returned. If the pathname corresponds<a name="line.2802"></a>
<span class="sourceLineNo">2803</span>     * to a file, only that file will be listed.  The server may or may not<a name="line.2803"></a>
<span class="sourceLineNo">2804</span>     * expand glob expressions.<a name="line.2804"></a>
<span class="sourceLineNo">2805</span>     * &lt;p&gt;<a name="line.2805"></a>
<span class="sourceLineNo">2806</span>     * @param pathname  The file or directory to list.<a name="line.2806"></a>
<span class="sourceLineNo">2807</span>     *                  Warning: the server may treat a leading '-' as an<a name="line.2807"></a>
<span class="sourceLineNo">2808</span>     *                  option introducer. If so, try using an absolute path,<a name="line.2808"></a>
<span class="sourceLineNo">2809</span>     *                  or prefix the path with ./ (unix style servers).<a name="line.2809"></a>
<span class="sourceLineNo">2810</span>     *                  Some servers may support "--" as meaning end of options,<a name="line.2810"></a>
<span class="sourceLineNo">2811</span>     *                  in which case "-- -xyz" should work.<a name="line.2811"></a>
<span class="sourceLineNo">2812</span>     * @return The list of filenames contained in the given path.  null if<a name="line.2812"></a>
<span class="sourceLineNo">2813</span>     *     the list could not be obtained.  If there are no filenames in<a name="line.2813"></a>
<span class="sourceLineNo">2814</span>     *     the directory, a zero-length array is returned.<a name="line.2814"></a>
<span class="sourceLineNo">2815</span>     * @exception FTPConnectionClosedException<a name="line.2815"></a>
<span class="sourceLineNo">2816</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2816"></a>
<span class="sourceLineNo">2817</span>     *      of the client being idle or some other reason causing the server<a name="line.2817"></a>
<span class="sourceLineNo">2818</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2818"></a>
<span class="sourceLineNo">2819</span>     *      as an IOException or independently as itself.<a name="line.2819"></a>
<span class="sourceLineNo">2820</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2820"></a>
<span class="sourceLineNo">2821</span>     *      command to the server or receiving a reply from the server.<a name="line.2821"></a>
<span class="sourceLineNo">2822</span>     */<a name="line.2822"></a>
<span class="sourceLineNo">2823</span>    public String[] listNames(String pathname) throws IOException<a name="line.2823"></a>
<span class="sourceLineNo">2824</span>    {<a name="line.2824"></a>
<span class="sourceLineNo">2825</span>        Socket socket = _openDataConnection_(FTPCmd.NLST, getListArguments(pathname));<a name="line.2825"></a>
<span class="sourceLineNo">2826</span><a name="line.2826"></a>
<span class="sourceLineNo">2827</span>        if (socket == null) {<a name="line.2827"></a>
<span class="sourceLineNo">2828</span>            return null;<a name="line.2828"></a>
<span class="sourceLineNo">2829</span>        }<a name="line.2829"></a>
<span class="sourceLineNo">2830</span><a name="line.2830"></a>
<span class="sourceLineNo">2831</span>        BufferedReader reader =<a name="line.2831"></a>
<span class="sourceLineNo">2832</span>            new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()));<a name="line.2832"></a>
<span class="sourceLineNo">2833</span><a name="line.2833"></a>
<span class="sourceLineNo">2834</span>        ArrayList&lt;String&gt; results = new ArrayList&lt;String&gt;();<a name="line.2834"></a>
<span class="sourceLineNo">2835</span>        String line;<a name="line.2835"></a>
<span class="sourceLineNo">2836</span>        while ((line = reader.readLine()) != null) {<a name="line.2836"></a>
<span class="sourceLineNo">2837</span>            results.add(line);<a name="line.2837"></a>
<span class="sourceLineNo">2838</span>        }<a name="line.2838"></a>
<span class="sourceLineNo">2839</span><a name="line.2839"></a>
<span class="sourceLineNo">2840</span>        reader.close();<a name="line.2840"></a>
<span class="sourceLineNo">2841</span>        socket.close();<a name="line.2841"></a>
<span class="sourceLineNo">2842</span><a name="line.2842"></a>
<span class="sourceLineNo">2843</span>        if (completePendingCommand())<a name="line.2843"></a>
<span class="sourceLineNo">2844</span>        {<a name="line.2844"></a>
<span class="sourceLineNo">2845</span>            String[] names = new String[ results.size() ];<a name="line.2845"></a>
<span class="sourceLineNo">2846</span>            return results.toArray(names);<a name="line.2846"></a>
<span class="sourceLineNo">2847</span>        }<a name="line.2847"></a>
<span class="sourceLineNo">2848</span><a name="line.2848"></a>
<span class="sourceLineNo">2849</span>        return null;<a name="line.2849"></a>
<span class="sourceLineNo">2850</span>    }<a name="line.2850"></a>
<span class="sourceLineNo">2851</span><a name="line.2851"></a>
<span class="sourceLineNo">2852</span><a name="line.2852"></a>
<span class="sourceLineNo">2853</span>    /**<a name="line.2853"></a>
<span class="sourceLineNo">2854</span>     * Obtain a list of filenames in the current working directory<a name="line.2854"></a>
<span class="sourceLineNo">2855</span>     * This information is obtained through the NLST command.  If the current<a name="line.2855"></a>
<span class="sourceLineNo">2856</span>     * directory contains no files, a zero length array is returned only<a name="line.2856"></a>
<span class="sourceLineNo">2857</span>     * if the FTP server returned a positive completion code, otherwise,<a name="line.2857"></a>
<span class="sourceLineNo">2858</span>     * null is returned (the FTP server returned a 550 error No files found.).<a name="line.2858"></a>
<span class="sourceLineNo">2859</span>     * If the directory is not empty, an array of filenames in the directory is<a name="line.2859"></a>
<span class="sourceLineNo">2860</span>     * returned.<a name="line.2860"></a>
<span class="sourceLineNo">2861</span>     * &lt;p&gt;<a name="line.2861"></a>
<span class="sourceLineNo">2862</span>     * @return The list of filenames contained in the current working<a name="line.2862"></a>
<span class="sourceLineNo">2863</span>     *     directory.  null if the list could not be obtained.<a name="line.2863"></a>
<span class="sourceLineNo">2864</span>     *     If there are no filenames in the directory, a zero-length array<a name="line.2864"></a>
<span class="sourceLineNo">2865</span>     *     is returned.<a name="line.2865"></a>
<span class="sourceLineNo">2866</span>     * @exception FTPConnectionClosedException<a name="line.2866"></a>
<span class="sourceLineNo">2867</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.2867"></a>
<span class="sourceLineNo">2868</span>     *      of the client being idle or some other reason causing the server<a name="line.2868"></a>
<span class="sourceLineNo">2869</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.2869"></a>
<span class="sourceLineNo">2870</span>     *      as an IOException or independently as itself.<a name="line.2870"></a>
<span class="sourceLineNo">2871</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.2871"></a>
<span class="sourceLineNo">2872</span>     *      command to the server or receiving a reply from the server.<a name="line.2872"></a>
<span class="sourceLineNo">2873</span>     */<a name="line.2873"></a>
<span class="sourceLineNo">2874</span>    public String[] listNames() throws IOException<a name="line.2874"></a>
<span class="sourceLineNo">2875</span>    {<a name="line.2875"></a>
<span class="sourceLineNo">2876</span>        return listNames(null);<a name="line.2876"></a>
<span class="sourceLineNo">2877</span>    }<a name="line.2877"></a>
<span class="sourceLineNo">2878</span><a name="line.2878"></a>
<span class="sourceLineNo">2879</span><a name="line.2879"></a>
<span class="sourceLineNo">2880</span><a name="line.2880"></a>
<span class="sourceLineNo">2881</span>    /**<a name="line.2881"></a>
<span class="sourceLineNo">2882</span>     * Using the default system autodetect mechanism, obtain a<a name="line.2882"></a>
<span class="sourceLineNo">2883</span>     * list of file information for the current working directory<a name="line.2883"></a>
<span class="sourceLineNo">2884</span>     * or for just a single file.<a name="line.2884"></a>
<span class="sourceLineNo">2885</span>     * &lt;p&gt;<a name="line.2885"></a>
<span class="sourceLineNo">2886</span>     * This information is obtained through the LIST command.  The contents of<a name="line.2886"></a>
<span class="sourceLineNo">2887</span>     * the returned array is determined by the&lt;code&gt; FTPFileEntryParser &lt;/code&gt;<a name="line.2887"></a>
<span class="sourceLineNo">2888</span>     * used.<a name="line.2888"></a>
<span class="sourceLineNo">2889</span>     * &lt;p&gt;<a name="line.2889"></a>
<span class="sourceLineNo">2890</span>     * @param pathname  The file or directory to list.  Since the server may<a name="line.2890"></a>
<span class="sourceLineNo">2891</span>     *                  or may not expand glob expressions, using them here<a name="line.2891"></a>
<span class="sourceLineNo">2892</span>     *                  is not recommended and may well cause this method to<a name="line.2892"></a>
<span class="sourceLineNo">2893</span>     *                  fail.<a name="line.2893"></a>
<span class="sourceLineNo">2894</span>     *                  Also, some servers treat a leading '-' as being an option.<a name="line.2894"></a>
<span class="sourceLineNo">2895</span>     *                  To avoid this interpretation, use an absolute pathname<a name="line.2895"></a>
<span class="sourceLineNo">2896</span>     *                  or prefix the pathname with ./ (unix style servers).<a name="line.2896"></a>
<span class="sourceLineNo">2897</span>     *                  Some servers may support "--" as meaning end of options,<a name="line.2897"></a>
<span class="sourceLineNo">2898</span>     *                  in which case "-- -xyz" should work.<a name="line.2898"></a>
<span class="sourceLineNo">2899</span>     *<a name="line.2899"></a>
<span class="sourceLineNo">2900</span>     * @return The list of file information contained in the given path in<a name="line.2900"></a>
<span class="sourceLineNo">2901</span>     *         the format determined by the autodetection mechanism<a name="line.2901"></a>
<span class="sourceLineNo">2902</span>     * @exception FTPConnectionClosedException<a name="line.2902"></a>
<span class="sourceLineNo">2903</span>     *                   If the FTP server prematurely closes the connection<a name="line.2903"></a>
<span class="sourceLineNo">2904</span>     *                   as a result of the client being idle or some other<a name="line.2904"></a>
<span class="sourceLineNo">2905</span>     *                   reason causing the server to send FTP reply code 421.<a name="line.2905"></a>
<span class="sourceLineNo">2906</span>     *                   This exception may be caught either as an IOException<a name="line.2906"></a>
<span class="sourceLineNo">2907</span>     *                   or independently as itself.<a name="line.2907"></a>
<span class="sourceLineNo">2908</span>     * @exception IOException<a name="line.2908"></a>
<span class="sourceLineNo">2909</span>     *                   If an I/O error occurs while either sending a<a name="line.2909"></a>
<span class="sourceLineNo">2910</span>     *                   command to the server or receiving a reply<a name="line.2910"></a>
<span class="sourceLineNo">2911</span>     *                   from the server.<a name="line.2911"></a>
<span class="sourceLineNo">2912</span>     * @exception org.apache.commons.net.ftp.parser.ParserInitializationException<a name="line.2912"></a>
<span class="sourceLineNo">2913</span>     *                   Thrown if the parserKey parameter cannot be<a name="line.2913"></a>
<span class="sourceLineNo">2914</span>     *                   resolved by the selected parser factory.<a name="line.2914"></a>
<span class="sourceLineNo">2915</span>     *                   In the DefaultFTPEntryParserFactory, this will<a name="line.2915"></a>
<span class="sourceLineNo">2916</span>     *                   happen when parserKey is neither<a name="line.2916"></a>
<span class="sourceLineNo">2917</span>     *                   the fully qualified class name of a class<a name="line.2917"></a>
<span class="sourceLineNo">2918</span>     *                   implementing the interface<a name="line.2918"></a>
<span class="sourceLineNo">2919</span>     *                   org.apache.commons.net.ftp.FTPFileEntryParser<a name="line.2919"></a>
<span class="sourceLineNo">2920</span>     *                   nor a string containing one of the recognized keys<a name="line.2920"></a>
<span class="sourceLineNo">2921</span>     *                   mapping to such a parser or if class loader<a name="line.2921"></a>
<span class="sourceLineNo">2922</span>     *                   security issues prevent its being loaded.<a name="line.2922"></a>
<span class="sourceLineNo">2923</span>     * @see org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory<a name="line.2923"></a>
<span class="sourceLineNo">2924</span>     * @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory<a name="line.2924"></a>
<span class="sourceLineNo">2925</span>     * @see org.apache.commons.net.ftp.FTPFileEntryParser<a name="line.2925"></a>
<span class="sourceLineNo">2926</span>     */<a name="line.2926"></a>
<span class="sourceLineNo">2927</span>    public FTPFile[] listFiles(String pathname)<a name="line.2927"></a>
<span class="sourceLineNo">2928</span>    throws IOException<a name="line.2928"></a>
<span class="sourceLineNo">2929</span>    {<a name="line.2929"></a>
<span class="sourceLineNo">2930</span>        FTPListParseEngine engine = initiateListParsing((String) null, pathname);<a name="line.2930"></a>
<span class="sourceLineNo">2931</span>        return engine.getFiles();<a name="line.2931"></a>
<span class="sourceLineNo">2932</span><a name="line.2932"></a>
<span class="sourceLineNo">2933</span>    }<a name="line.2933"></a>
<span class="sourceLineNo">2934</span><a name="line.2934"></a>
<span class="sourceLineNo">2935</span>    /**<a name="line.2935"></a>
<span class="sourceLineNo">2936</span>     * Using the default system autodetect mechanism, obtain a<a name="line.2936"></a>
<span class="sourceLineNo">2937</span>     * list of file information for the current working directory.<a name="line.2937"></a>
<span class="sourceLineNo">2938</span>     * &lt;p&gt;<a name="line.2938"></a>
<span class="sourceLineNo">2939</span>     * This information is obtained through the LIST command.  The contents of<a name="line.2939"></a>
<span class="sourceLineNo">2940</span>     * the returned array is determined by the&lt;code&gt; FTPFileEntryParser &lt;/code&gt;<a name="line.2940"></a>
<span class="sourceLineNo">2941</span>     * used.<a name="line.2941"></a>
<span class="sourceLineNo">2942</span>     * &lt;p&gt;<a name="line.2942"></a>
<span class="sourceLineNo">2943</span>     * @return The list of file information contained in the current directory<a name="line.2943"></a>
<span class="sourceLineNo">2944</span>     *         in the format determined by the autodetection mechanism.<a name="line.2944"></a>
<span class="sourceLineNo">2945</span>     *         &lt;p&gt;&lt;b&gt;<a name="line.2945"></a>
<span class="sourceLineNo">2946</span>     *         NOTE:&lt;/b&gt; This array may contain null members if any of the<a name="line.2946"></a>
<span class="sourceLineNo">2947</span>     *         individual file listings failed to parse.  The caller should<a name="line.2947"></a>
<span class="sourceLineNo">2948</span>     *         check each entry for null before referencing it.<a name="line.2948"></a>
<span class="sourceLineNo">2949</span>     * @exception FTPConnectionClosedException<a name="line.2949"></a>
<span class="sourceLineNo">2950</span>     *                   If the FTP server prematurely closes the connection<a name="line.2950"></a>
<span class="sourceLineNo">2951</span>     *                   as a result of the client being idle or some other<a name="line.2951"></a>
<span class="sourceLineNo">2952</span>     *                   reason causing the server to send FTP reply code 421.<a name="line.2952"></a>
<span class="sourceLineNo">2953</span>     *                   This exception may be caught either as an IOException<a name="line.2953"></a>
<span class="sourceLineNo">2954</span>     *                   or independently as itself.<a name="line.2954"></a>
<span class="sourceLineNo">2955</span>     * @exception IOException<a name="line.2955"></a>
<span class="sourceLineNo">2956</span>     *                   If an I/O error occurs while either sending a<a name="line.2956"></a>
<span class="sourceLineNo">2957</span>     *                   command to the server or receiving a reply<a name="line.2957"></a>
<span class="sourceLineNo">2958</span>     *                   from the server.<a name="line.2958"></a>
<span class="sourceLineNo">2959</span>     * @exception org.apache.commons.net.ftp.parser.ParserInitializationException<a name="line.2959"></a>
<span class="sourceLineNo">2960</span>     *                   Thrown if the parserKey parameter cannot be<a name="line.2960"></a>
<span class="sourceLineNo">2961</span>     *                   resolved by the selected parser factory.<a name="line.2961"></a>
<span class="sourceLineNo">2962</span>     *                   In the DefaultFTPEntryParserFactory, this will<a name="line.2962"></a>
<span class="sourceLineNo">2963</span>     *                   happen when parserKey is neither<a name="line.2963"></a>
<span class="sourceLineNo">2964</span>     *                   the fully qualified class name of a class<a name="line.2964"></a>
<span class="sourceLineNo">2965</span>     *                   implementing the interface<a name="line.2965"></a>
<span class="sourceLineNo">2966</span>     *                   org.apache.commons.net.ftp.FTPFileEntryParser<a name="line.2966"></a>
<span class="sourceLineNo">2967</span>     *                   nor a string containing one of the recognized keys<a name="line.2967"></a>
<span class="sourceLineNo">2968</span>     *                   mapping to such a parser or if class loader<a name="line.2968"></a>
<span class="sourceLineNo">2969</span>     *                   security issues prevent its being loaded.<a name="line.2969"></a>
<span class="sourceLineNo">2970</span>     * @see org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory<a name="line.2970"></a>
<span class="sourceLineNo">2971</span>     * @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory<a name="line.2971"></a>
<span class="sourceLineNo">2972</span>     * @see org.apache.commons.net.ftp.FTPFileEntryParser<a name="line.2972"></a>
<span class="sourceLineNo">2973</span>     */<a name="line.2973"></a>
<span class="sourceLineNo">2974</span>    public FTPFile[] listFiles()<a name="line.2974"></a>
<span class="sourceLineNo">2975</span>    throws IOException<a name="line.2975"></a>
<span class="sourceLineNo">2976</span>    {<a name="line.2976"></a>
<span class="sourceLineNo">2977</span>        return listFiles((String) null);<a name="line.2977"></a>
<span class="sourceLineNo">2978</span>    }<a name="line.2978"></a>
<span class="sourceLineNo">2979</span><a name="line.2979"></a>
<span class="sourceLineNo">2980</span>    /**<a name="line.2980"></a>
<span class="sourceLineNo">2981</span>     * Version of {@link #listFiles(String)} which allows a filter to be provided.<a name="line.2981"></a>
<span class="sourceLineNo">2982</span>     * For example: &lt;code&gt;listFiles("site", FTPFileFilters.DIRECTORY);&lt;/code&gt;<a name="line.2982"></a>
<span class="sourceLineNo">2983</span>     * @param pathname the initial path, may be null<a name="line.2983"></a>
<span class="sourceLineNo">2984</span>     * @param filter the filter, non-null<a name="line.2984"></a>
<span class="sourceLineNo">2985</span>     * @return the list of FTPFile entries.<a name="line.2985"></a>
<span class="sourceLineNo">2986</span>     * @throws IOException<a name="line.2986"></a>
<span class="sourceLineNo">2987</span>     * @since 2.2<a name="line.2987"></a>
<span class="sourceLineNo">2988</span>     */<a name="line.2988"></a>
<span class="sourceLineNo">2989</span>    public FTPFile[] listFiles(String pathname, FTPFileFilter filter)<a name="line.2989"></a>
<span class="sourceLineNo">2990</span>    throws IOException<a name="line.2990"></a>
<span class="sourceLineNo">2991</span>    {<a name="line.2991"></a>
<span class="sourceLineNo">2992</span>        FTPListParseEngine engine = initiateListParsing((String) null, pathname);<a name="line.2992"></a>
<span class="sourceLineNo">2993</span>        return engine.getFiles(filter);<a name="line.2993"></a>
<span class="sourceLineNo">2994</span><a name="line.2994"></a>
<span class="sourceLineNo">2995</span>    }<a name="line.2995"></a>
<span class="sourceLineNo">2996</span><a name="line.2996"></a>
<span class="sourceLineNo">2997</span>    /**<a name="line.2997"></a>
<span class="sourceLineNo">2998</span>     * Using the default system autodetect mechanism, obtain a<a name="line.2998"></a>
<span class="sourceLineNo">2999</span>     * list of directories contained in the current working directory.<a name="line.2999"></a>
<span class="sourceLineNo">3000</span>     * &lt;p&gt;<a name="line.3000"></a>
<span class="sourceLineNo">3001</span>     * This information is obtained through the LIST command.  The contents of<a name="line.3001"></a>
<span class="sourceLineNo">3002</span>     * the returned array is determined by the&lt;code&gt; FTPFileEntryParser &lt;/code&gt;<a name="line.3002"></a>
<span class="sourceLineNo">3003</span>     * used.<a name="line.3003"></a>
<span class="sourceLineNo">3004</span>     * &lt;p&gt;<a name="line.3004"></a>
<span class="sourceLineNo">3005</span>     * @return The list of directories contained in the current directory<a name="line.3005"></a>
<span class="sourceLineNo">3006</span>     *         in the format determined by the autodetection mechanism.<a name="line.3006"></a>
<span class="sourceLineNo">3007</span>     *<a name="line.3007"></a>
<span class="sourceLineNo">3008</span>     * @exception FTPConnectionClosedException<a name="line.3008"></a>
<span class="sourceLineNo">3009</span>     *                   If the FTP server prematurely closes the connection<a name="line.3009"></a>
<span class="sourceLineNo">3010</span>     *                   as a result of the client being idle or some other<a name="line.3010"></a>
<span class="sourceLineNo">3011</span>     *                   reason causing the server to send FTP reply code 421.<a name="line.3011"></a>
<span class="sourceLineNo">3012</span>     *                   This exception may be caught either as an IOException<a name="line.3012"></a>
<span class="sourceLineNo">3013</span>     *                   or independently as itself.<a name="line.3013"></a>
<span class="sourceLineNo">3014</span>     * @exception IOException<a name="line.3014"></a>
<span class="sourceLineNo">3015</span>     *                   If an I/O error occurs while either sending a<a name="line.3015"></a>
<span class="sourceLineNo">3016</span>     *                   command to the server or receiving a reply<a name="line.3016"></a>
<span class="sourceLineNo">3017</span>     *                   from the server.<a name="line.3017"></a>
<span class="sourceLineNo">3018</span>     * @exception org.apache.commons.net.ftp.parser.ParserInitializationException<a name="line.3018"></a>
<span class="sourceLineNo">3019</span>     *                   Thrown if the parserKey parameter cannot be<a name="line.3019"></a>
<span class="sourceLineNo">3020</span>     *                   resolved by the selected parser factory.<a name="line.3020"></a>
<span class="sourceLineNo">3021</span>     *                   In the DefaultFTPEntryParserFactory, this will<a name="line.3021"></a>
<span class="sourceLineNo">3022</span>     *                   happen when parserKey is neither<a name="line.3022"></a>
<span class="sourceLineNo">3023</span>     *                   the fully qualified class name of a class<a name="line.3023"></a>
<span class="sourceLineNo">3024</span>     *                   implementing the interface<a name="line.3024"></a>
<span class="sourceLineNo">3025</span>     *                   org.apache.commons.net.ftp.FTPFileEntryParser<a name="line.3025"></a>
<span class="sourceLineNo">3026</span>     *                   nor a string containing one of the recognized keys<a name="line.3026"></a>
<span class="sourceLineNo">3027</span>     *                   mapping to such a parser or if class loader<a name="line.3027"></a>
<span class="sourceLineNo">3028</span>     *                   security issues prevent its being loaded.<a name="line.3028"></a>
<span class="sourceLineNo">3029</span>     * @see org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory<a name="line.3029"></a>
<span class="sourceLineNo">3030</span>     * @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory<a name="line.3030"></a>
<span class="sourceLineNo">3031</span>     * @see org.apache.commons.net.ftp.FTPFileEntryParser<a name="line.3031"></a>
<span class="sourceLineNo">3032</span>     * @since 3.0<a name="line.3032"></a>
<span class="sourceLineNo">3033</span>     */<a name="line.3033"></a>
<span class="sourceLineNo">3034</span>    public FTPFile[] listDirectories() throws IOException {<a name="line.3034"></a>
<span class="sourceLineNo">3035</span>        return listDirectories((String) null);<a name="line.3035"></a>
<span class="sourceLineNo">3036</span>    }<a name="line.3036"></a>
<span class="sourceLineNo">3037</span><a name="line.3037"></a>
<span class="sourceLineNo">3038</span>    /**<a name="line.3038"></a>
<span class="sourceLineNo">3039</span>     * Using the default system autodetect mechanism, obtain a<a name="line.3039"></a>
<span class="sourceLineNo">3040</span>     * list of directories contained in the specified directory.<a name="line.3040"></a>
<span class="sourceLineNo">3041</span>     * &lt;p&gt;<a name="line.3041"></a>
<span class="sourceLineNo">3042</span>     * This information is obtained through the LIST command.  The contents of<a name="line.3042"></a>
<span class="sourceLineNo">3043</span>     * the returned array is determined by the&lt;code&gt; FTPFileEntryParser &lt;/code&gt;<a name="line.3043"></a>
<span class="sourceLineNo">3044</span>     * used.<a name="line.3044"></a>
<span class="sourceLineNo">3045</span>     * &lt;p&gt;<a name="line.3045"></a>
<span class="sourceLineNo">3046</span>     * @return The list of directories contained in the specified directory<a name="line.3046"></a>
<span class="sourceLineNo">3047</span>     *         in the format determined by the autodetection mechanism.<a name="line.3047"></a>
<span class="sourceLineNo">3048</span>     *<a name="line.3048"></a>
<span class="sourceLineNo">3049</span>     * @exception FTPConnectionClosedException<a name="line.3049"></a>
<span class="sourceLineNo">3050</span>     *                   If the FTP server prematurely closes the connection<a name="line.3050"></a>
<span class="sourceLineNo">3051</span>     *                   as a result of the client being idle or some other<a name="line.3051"></a>
<span class="sourceLineNo">3052</span>     *                   reason causing the server to send FTP reply code 421.<a name="line.3052"></a>
<span class="sourceLineNo">3053</span>     *                   This exception may be caught either as an IOException<a name="line.3053"></a>
<span class="sourceLineNo">3054</span>     *                   or independently as itself.<a name="line.3054"></a>
<span class="sourceLineNo">3055</span>     * @exception IOException<a name="line.3055"></a>
<span class="sourceLineNo">3056</span>     *                   If an I/O error occurs while either sending a<a name="line.3056"></a>
<span class="sourceLineNo">3057</span>     *                   command to the server or receiving a reply<a name="line.3057"></a>
<span class="sourceLineNo">3058</span>     *                   from the server.<a name="line.3058"></a>
<span class="sourceLineNo">3059</span>     * @exception org.apache.commons.net.ftp.parser.ParserInitializationException<a name="line.3059"></a>
<span class="sourceLineNo">3060</span>     *                   Thrown if the parserKey parameter cannot be<a name="line.3060"></a>
<span class="sourceLineNo">3061</span>     *                   resolved by the selected parser factory.<a name="line.3061"></a>
<span class="sourceLineNo">3062</span>     *                   In the DefaultFTPEntryParserFactory, this will<a name="line.3062"></a>
<span class="sourceLineNo">3063</span>     *                   happen when parserKey is neither<a name="line.3063"></a>
<span class="sourceLineNo">3064</span>     *                   the fully qualified class name of a class<a name="line.3064"></a>
<span class="sourceLineNo">3065</span>     *                   implementing the interface<a name="line.3065"></a>
<span class="sourceLineNo">3066</span>     *                   org.apache.commons.net.ftp.FTPFileEntryParser<a name="line.3066"></a>
<span class="sourceLineNo">3067</span>     *                   nor a string containing one of the recognized keys<a name="line.3067"></a>
<span class="sourceLineNo">3068</span>     *                   mapping to such a parser or if class loader<a name="line.3068"></a>
<span class="sourceLineNo">3069</span>     *                   security issues prevent its being loaded.<a name="line.3069"></a>
<span class="sourceLineNo">3070</span>     * @see org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory<a name="line.3070"></a>
<span class="sourceLineNo">3071</span>     * @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory<a name="line.3071"></a>
<span class="sourceLineNo">3072</span>     * @see org.apache.commons.net.ftp.FTPFileEntryParser<a name="line.3072"></a>
<span class="sourceLineNo">3073</span>     * @since 3.0<a name="line.3073"></a>
<span class="sourceLineNo">3074</span>     */<a name="line.3074"></a>
<span class="sourceLineNo">3075</span>    public FTPFile[] listDirectories(String parent) throws IOException {<a name="line.3075"></a>
<span class="sourceLineNo">3076</span>        return listFiles(parent, FTPFileFilters.DIRECTORIES);<a name="line.3076"></a>
<span class="sourceLineNo">3077</span>    }<a name="line.3077"></a>
<span class="sourceLineNo">3078</span><a name="line.3078"></a>
<span class="sourceLineNo">3079</span>    /**<a name="line.3079"></a>
<span class="sourceLineNo">3080</span>     * Using the default autodetect mechanism, initialize an FTPListParseEngine<a name="line.3080"></a>
<span class="sourceLineNo">3081</span>     * object containing a raw file information for the current working<a name="line.3081"></a>
<span class="sourceLineNo">3082</span>     * directory on the server<a name="line.3082"></a>
<span class="sourceLineNo">3083</span>     * This information is obtained through the LIST command.  This object<a name="line.3083"></a>
<span class="sourceLineNo">3084</span>     * is then capable of being iterated to return a sequence of FTPFile<a name="line.3084"></a>
<span class="sourceLineNo">3085</span>     * objects with information filled in by the<a name="line.3085"></a>
<span class="sourceLineNo">3086</span>     * &lt;code&gt; FTPFileEntryParser &lt;/code&gt; used.<a name="line.3086"></a>
<span class="sourceLineNo">3087</span>     * &lt;p&gt;<a name="line.3087"></a>
<span class="sourceLineNo">3088</span>     * This method differs from using the listFiles() methods in that<a name="line.3088"></a>
<span class="sourceLineNo">3089</span>     * expensive FTPFile objects are not created until needed which may be<a name="line.3089"></a>
<span class="sourceLineNo">3090</span>     * an advantage on large lists.<a name="line.3090"></a>
<span class="sourceLineNo">3091</span>     *<a name="line.3091"></a>
<span class="sourceLineNo">3092</span>     * @return A FTPListParseEngine object that holds the raw information and<a name="line.3092"></a>
<span class="sourceLineNo">3093</span>     * is capable of providing parsed FTPFile objects, one for each file<a name="line.3093"></a>
<span class="sourceLineNo">3094</span>     * containing information contained in the given path in the format<a name="line.3094"></a>
<span class="sourceLineNo">3095</span>     * determined by the &lt;code&gt; parser &lt;/code&gt; parameter.   Null will be<a name="line.3095"></a>
<span class="sourceLineNo">3096</span>     * returned if a data connection cannot be opened.  If the current working<a name="line.3096"></a>
<span class="sourceLineNo">3097</span>     * directory contains no files, an empty array will be the return.<a name="line.3097"></a>
<span class="sourceLineNo">3098</span>     *<a name="line.3098"></a>
<span class="sourceLineNo">3099</span>     * @exception FTPConnectionClosedException<a name="line.3099"></a>
<span class="sourceLineNo">3100</span>     *                   If the FTP server prematurely closes the connection as a result<a name="line.3100"></a>
<span class="sourceLineNo">3101</span>     *                   of the client being idle or some other reason causing the server<a name="line.3101"></a>
<span class="sourceLineNo">3102</span>     *                   to send FTP reply code 421.  This exception may be caught either<a name="line.3102"></a>
<span class="sourceLineNo">3103</span>     *                   as an IOException or independently as itself.<a name="line.3103"></a>
<span class="sourceLineNo">3104</span>     * @exception IOException<a name="line.3104"></a>
<span class="sourceLineNo">3105</span>     *                   If an I/O error occurs while either sending a<a name="line.3105"></a>
<span class="sourceLineNo">3106</span>     *                   command to the server or receiving a reply from the server.<a name="line.3106"></a>
<span class="sourceLineNo">3107</span>     * @exception org.apache.commons.net.ftp.parser.ParserInitializationException<a name="line.3107"></a>
<span class="sourceLineNo">3108</span>     *                   Thrown if the autodetect mechanism cannot<a name="line.3108"></a>
<span class="sourceLineNo">3109</span>     *                   resolve the type of system we are connected with.<a name="line.3109"></a>
<span class="sourceLineNo">3110</span>     * @see FTPListParseEngine<a name="line.3110"></a>
<span class="sourceLineNo">3111</span>     */<a name="line.3111"></a>
<span class="sourceLineNo">3112</span>    public FTPListParseEngine initiateListParsing()<a name="line.3112"></a>
<span class="sourceLineNo">3113</span>    throws IOException<a name="line.3113"></a>
<span class="sourceLineNo">3114</span>    {<a name="line.3114"></a>
<span class="sourceLineNo">3115</span>        return initiateListParsing((String) null);<a name="line.3115"></a>
<span class="sourceLineNo">3116</span>    }<a name="line.3116"></a>
<span class="sourceLineNo">3117</span><a name="line.3117"></a>
<span class="sourceLineNo">3118</span>    /**<a name="line.3118"></a>
<span class="sourceLineNo">3119</span>     * Using the default autodetect mechanism, initialize an FTPListParseEngine<a name="line.3119"></a>
<span class="sourceLineNo">3120</span>     * object containing a raw file information for the supplied directory.<a name="line.3120"></a>
<span class="sourceLineNo">3121</span>     * This information is obtained through the LIST command.  This object<a name="line.3121"></a>
<span class="sourceLineNo">3122</span>     * is then capable of being iterated to return a sequence of FTPFile<a name="line.3122"></a>
<span class="sourceLineNo">3123</span>     * objects with information filled in by the<a name="line.3123"></a>
<span class="sourceLineNo">3124</span>     * &lt;code&gt; FTPFileEntryParser &lt;/code&gt; used.<a name="line.3124"></a>
<span class="sourceLineNo">3125</span>     * &lt;p&gt;<a name="line.3125"></a>
<span class="sourceLineNo">3126</span>     * The server may or may not expand glob expressions.  You should avoid<a name="line.3126"></a>
<span class="sourceLineNo">3127</span>     * using glob expressions because the return format for glob listings<a name="line.3127"></a>
<span class="sourceLineNo">3128</span>     * differs from server to server and will likely cause this method to fail.<a name="line.3128"></a>
<span class="sourceLineNo">3129</span>     * &lt;p&gt;<a name="line.3129"></a>
<span class="sourceLineNo">3130</span>     * This method differs from using the listFiles() methods in that<a name="line.3130"></a>
<span class="sourceLineNo">3131</span>     * expensive FTPFile objects are not created until needed which may be<a name="line.3131"></a>
<span class="sourceLineNo">3132</span>     * an advantage on large lists.<a name="line.3132"></a>
<span class="sourceLineNo">3133</span>     * &lt;p&gt;<a name="line.3133"></a>
<span class="sourceLineNo">3134</span>     * &lt;pre&gt;<a name="line.3134"></a>
<span class="sourceLineNo">3135</span>     *    FTPClient f=FTPClient();<a name="line.3135"></a>
<span class="sourceLineNo">3136</span>     *    f.connect(server);<a name="line.3136"></a>
<span class="sourceLineNo">3137</span>     *    f.login(username, password);<a name="line.3137"></a>
<span class="sourceLineNo">3138</span>     *    FTPListParseEngine engine = f.initiateListParsing(directory);<a name="line.3138"></a>
<span class="sourceLineNo">3139</span>     *<a name="line.3139"></a>
<span class="sourceLineNo">3140</span>     *    while (engine.hasNext()) {<a name="line.3140"></a>
<span class="sourceLineNo">3141</span>     *       FTPFile[] files = engine.getNext(25);  // "page size" you want<a name="line.3141"></a>
<span class="sourceLineNo">3142</span>     *       //do whatever you want with these files, display them, etc.<a name="line.3142"></a>
<span class="sourceLineNo">3143</span>     *       //expensive FTPFile objects not created until needed.<a name="line.3143"></a>
<span class="sourceLineNo">3144</span>     *    }<a name="line.3144"></a>
<span class="sourceLineNo">3145</span>     * &lt;/pre&gt;<a name="line.3145"></a>
<span class="sourceLineNo">3146</span>     *<a name="line.3146"></a>
<span class="sourceLineNo">3147</span>     * @return A FTPListParseEngine object that holds the raw information and<a name="line.3147"></a>
<span class="sourceLineNo">3148</span>     * is capable of providing parsed FTPFile objects, one for each file<a name="line.3148"></a>
<span class="sourceLineNo">3149</span>     * containing information contained in the given path in the format<a name="line.3149"></a>
<span class="sourceLineNo">3150</span>     * determined by the &lt;code&gt; parser &lt;/code&gt; parameter.   Null will be<a name="line.3150"></a>
<span class="sourceLineNo">3151</span>     * returned if a data connection cannot be opened.  If the current working<a name="line.3151"></a>
<span class="sourceLineNo">3152</span>     * directory contains no files, an empty array will be the return.<a name="line.3152"></a>
<span class="sourceLineNo">3153</span>     *<a name="line.3153"></a>
<span class="sourceLineNo">3154</span>     * @exception FTPConnectionClosedException<a name="line.3154"></a>
<span class="sourceLineNo">3155</span>     *                   If the FTP server prematurely closes the connection as a result<a name="line.3155"></a>
<span class="sourceLineNo">3156</span>     *                   of the client being idle or some other reason causing the server<a name="line.3156"></a>
<span class="sourceLineNo">3157</span>     *                   to send FTP reply code 421.  This exception may be caught either<a name="line.3157"></a>
<span class="sourceLineNo">3158</span>     *                   as an IOException or independently as itself.<a name="line.3158"></a>
<span class="sourceLineNo">3159</span>     * @exception IOException<a name="line.3159"></a>
<span class="sourceLineNo">3160</span>     *                   If an I/O error occurs while either sending a<a name="line.3160"></a>
<span class="sourceLineNo">3161</span>     *                   command to the server or receiving a reply from the server.<a name="line.3161"></a>
<span class="sourceLineNo">3162</span>     * @exception org.apache.commons.net.ftp.parser.ParserInitializationException<a name="line.3162"></a>
<span class="sourceLineNo">3163</span>     *                   Thrown if the autodetect mechanism cannot<a name="line.3163"></a>
<span class="sourceLineNo">3164</span>     *                   resolve the type of system we are connected with.<a name="line.3164"></a>
<span class="sourceLineNo">3165</span>     * @see FTPListParseEngine<a name="line.3165"></a>
<span class="sourceLineNo">3166</span>     */<a name="line.3166"></a>
<span class="sourceLineNo">3167</span>    public FTPListParseEngine initiateListParsing(<a name="line.3167"></a>
<span class="sourceLineNo">3168</span>            String pathname)<a name="line.3168"></a>
<span class="sourceLineNo">3169</span>    throws IOException<a name="line.3169"></a>
<span class="sourceLineNo">3170</span>    {<a name="line.3170"></a>
<span class="sourceLineNo">3171</span>        return initiateListParsing((String) null, pathname);<a name="line.3171"></a>
<span class="sourceLineNo">3172</span>    }<a name="line.3172"></a>
<span class="sourceLineNo">3173</span><a name="line.3173"></a>
<span class="sourceLineNo">3174</span>    /**<a name="line.3174"></a>
<span class="sourceLineNo">3175</span>     * Using the supplied parser key, initialize an FTPListParseEngine<a name="line.3175"></a>
<span class="sourceLineNo">3176</span>     * object containing a raw file information for the supplied directory.<a name="line.3176"></a>
<span class="sourceLineNo">3177</span>     * This information is obtained through the LIST command.  This object<a name="line.3177"></a>
<span class="sourceLineNo">3178</span>     * is then capable of being iterated to return a sequence of FTPFile<a name="line.3178"></a>
<span class="sourceLineNo">3179</span>     * objects with information filled in by the<a name="line.3179"></a>
<span class="sourceLineNo">3180</span>     * &lt;code&gt; FTPFileEntryParser &lt;/code&gt; used.<a name="line.3180"></a>
<span class="sourceLineNo">3181</span>     * &lt;p&gt;<a name="line.3181"></a>
<span class="sourceLineNo">3182</span>     * The server may or may not expand glob expressions.  You should avoid<a name="line.3182"></a>
<span class="sourceLineNo">3183</span>     * using glob expressions because the return format for glob listings<a name="line.3183"></a>
<span class="sourceLineNo">3184</span>     * differs from server to server and will likely cause this method to fail.<a name="line.3184"></a>
<span class="sourceLineNo">3185</span>     * &lt;p&gt;<a name="line.3185"></a>
<span class="sourceLineNo">3186</span>     * This method differs from using the listFiles() methods in that<a name="line.3186"></a>
<span class="sourceLineNo">3187</span>     * expensive FTPFile objects are not created until needed which may be<a name="line.3187"></a>
<span class="sourceLineNo">3188</span>     * an advantage on large lists.<a name="line.3188"></a>
<span class="sourceLineNo">3189</span>     *<a name="line.3189"></a>
<span class="sourceLineNo">3190</span>     * @param parserKey A string representing a designated code or fully-qualified<a name="line.3190"></a>
<span class="sourceLineNo">3191</span>     * class name of an  &lt;code&gt; FTPFileEntryParser &lt;/code&gt; that should be<a name="line.3191"></a>
<span class="sourceLineNo">3192</span>     *               used to parse each server file listing.<a name="line.3192"></a>
<span class="sourceLineNo">3193</span>     *               May be {@code null}, in which case the code checks first<a name="line.3193"></a>
<span class="sourceLineNo">3194</span>     *               the system property {@link #FTP_SYSTEM_TYPE}, and if that is<a name="line.3194"></a>
<span class="sourceLineNo">3195</span>     *               not defined the SYST command is used to provide the value.<a name="line.3195"></a>
<span class="sourceLineNo">3196</span>     *               To allow for arbitrary system types, the return from the<a name="line.3196"></a>
<span class="sourceLineNo">3197</span>     *               SYST command is used to look up an alias for the type in the<a name="line.3197"></a>
<span class="sourceLineNo">3198</span>     *               {@link #SYSTEM_TYPE_PROPERTIES} properties file if it is available.<a name="line.3198"></a>
<span class="sourceLineNo">3199</span>     *<a name="line.3199"></a>
<span class="sourceLineNo">3200</span>     * @return A FTPListParseEngine object that holds the raw information and<a name="line.3200"></a>
<span class="sourceLineNo">3201</span>     * is capable of providing parsed FTPFile objects, one for each file<a name="line.3201"></a>
<span class="sourceLineNo">3202</span>     * containing information contained in the given path in the format<a name="line.3202"></a>
<span class="sourceLineNo">3203</span>     * determined by the &lt;code&gt; parser &lt;/code&gt; parameter.   Null will be<a name="line.3203"></a>
<span class="sourceLineNo">3204</span>     * returned if a data connection cannot be opened.  If the current working<a name="line.3204"></a>
<span class="sourceLineNo">3205</span>     * directory contains no files, an empty array will be the return.<a name="line.3205"></a>
<span class="sourceLineNo">3206</span>     *<a name="line.3206"></a>
<span class="sourceLineNo">3207</span>     * @exception FTPConnectionClosedException<a name="line.3207"></a>
<span class="sourceLineNo">3208</span>     *                   If the FTP server prematurely closes the connection as a result<a name="line.3208"></a>
<span class="sourceLineNo">3209</span>     *                   of the client being idle or some other reason causing the server<a name="line.3209"></a>
<span class="sourceLineNo">3210</span>     *                   to send FTP reply code 421.  This exception may be caught either<a name="line.3210"></a>
<span class="sourceLineNo">3211</span>     *                   as an IOException or independently as itself.<a name="line.3211"></a>
<span class="sourceLineNo">3212</span>     * @exception IOException<a name="line.3212"></a>
<span class="sourceLineNo">3213</span>     *                   If an I/O error occurs while either sending a<a name="line.3213"></a>
<span class="sourceLineNo">3214</span>     *                   command to the server or receiving a reply from the server.<a name="line.3214"></a>
<span class="sourceLineNo">3215</span>     * @exception org.apache.commons.net.ftp.parser.ParserInitializationException<a name="line.3215"></a>
<span class="sourceLineNo">3216</span>     *                   Thrown if the parserKey parameter cannot be<a name="line.3216"></a>
<span class="sourceLineNo">3217</span>     *                   resolved by the selected parser factory.<a name="line.3217"></a>
<span class="sourceLineNo">3218</span>     *                   In the DefaultFTPEntryParserFactory, this will<a name="line.3218"></a>
<span class="sourceLineNo">3219</span>     *                   happen when parserKey is neither<a name="line.3219"></a>
<span class="sourceLineNo">3220</span>     *                   the fully qualified class name of a class<a name="line.3220"></a>
<span class="sourceLineNo">3221</span>     *                   implementing the interface<a name="line.3221"></a>
<span class="sourceLineNo">3222</span>     *                   org.apache.commons.net.ftp.FTPFileEntryParser<a name="line.3222"></a>
<span class="sourceLineNo">3223</span>     *                   nor a string containing one of the recognized keys<a name="line.3223"></a>
<span class="sourceLineNo">3224</span>     *                   mapping to such a parser or if class loader<a name="line.3224"></a>
<span class="sourceLineNo">3225</span>     *                   security issues prevent its being loaded.<a name="line.3225"></a>
<span class="sourceLineNo">3226</span>     * @see FTPListParseEngine<a name="line.3226"></a>
<span class="sourceLineNo">3227</span>     */<a name="line.3227"></a>
<span class="sourceLineNo">3228</span>    public FTPListParseEngine initiateListParsing(<a name="line.3228"></a>
<span class="sourceLineNo">3229</span>            String parserKey, String pathname)<a name="line.3229"></a>
<span class="sourceLineNo">3230</span>    throws IOException<a name="line.3230"></a>
<span class="sourceLineNo">3231</span>    {<a name="line.3231"></a>
<span class="sourceLineNo">3232</span>        // We cache the value to avoid creation of a new object every<a name="line.3232"></a>
<span class="sourceLineNo">3233</span>        // time a file listing is generated.<a name="line.3233"></a>
<span class="sourceLineNo">3234</span>        if(__entryParser == null ||  ! __entryParserKey.equals(parserKey)) {<a name="line.3234"></a>
<span class="sourceLineNo">3235</span>            if (null != parserKey) {<a name="line.3235"></a>
<span class="sourceLineNo">3236</span>                // if a parser key was supplied in the parameters,<a name="line.3236"></a>
<span class="sourceLineNo">3237</span>                // use that to create the parser<a name="line.3237"></a>
<span class="sourceLineNo">3238</span>                __entryParser =<a name="line.3238"></a>
<span class="sourceLineNo">3239</span>                    __parserFactory.createFileEntryParser(parserKey);<a name="line.3239"></a>
<span class="sourceLineNo">3240</span>                __entryParserKey = parserKey;<a name="line.3240"></a>
<span class="sourceLineNo">3241</span><a name="line.3241"></a>
<span class="sourceLineNo">3242</span>            } else {<a name="line.3242"></a>
<span class="sourceLineNo">3243</span>                // if no parserKey was supplied, check for a configuration<a name="line.3243"></a>
<span class="sourceLineNo">3244</span>                // in the params, and if non-null, use that.<a name="line.3244"></a>
<span class="sourceLineNo">3245</span>                if (null != __configuration) {<a name="line.3245"></a>
<span class="sourceLineNo">3246</span>                    __entryParser =<a name="line.3246"></a>
<span class="sourceLineNo">3247</span>                        __parserFactory.createFileEntryParser(__configuration);<a name="line.3247"></a>
<span class="sourceLineNo">3248</span>                    __entryParserKey = __configuration.getServerSystemKey();<a name="line.3248"></a>
<span class="sourceLineNo">3249</span>                } else {<a name="line.3249"></a>
<span class="sourceLineNo">3250</span>                    // if a parserKey hasn't been supplied, and a configuration<a name="line.3250"></a>
<span class="sourceLineNo">3251</span>                    // hasn't been supplied, and the override property is not set<a name="line.3251"></a>
<span class="sourceLineNo">3252</span>                    // then autodetect by calling<a name="line.3252"></a>
<span class="sourceLineNo">3253</span>                    // the SYST command and use that to choose the parser.<a name="line.3253"></a>
<span class="sourceLineNo">3254</span>                    String systemType = System.getProperty(FTP_SYSTEM_TYPE);<a name="line.3254"></a>
<span class="sourceLineNo">3255</span>                    if (systemType == null) {<a name="line.3255"></a>
<span class="sourceLineNo">3256</span>                        systemType = getSystemType(); // cannot be null<a name="line.3256"></a>
<span class="sourceLineNo">3257</span>                        Properties override = getOverrideProperties();<a name="line.3257"></a>
<span class="sourceLineNo">3258</span>                        if (override != null) {<a name="line.3258"></a>
<span class="sourceLineNo">3259</span>                            String newType = override.getProperty(systemType);<a name="line.3259"></a>
<span class="sourceLineNo">3260</span>                            if (newType != null) {<a name="line.3260"></a>
<span class="sourceLineNo">3261</span>                                systemType = newType;<a name="line.3261"></a>
<span class="sourceLineNo">3262</span>                            }<a name="line.3262"></a>
<span class="sourceLineNo">3263</span>                        }<a name="line.3263"></a>
<span class="sourceLineNo">3264</span>                    }<a name="line.3264"></a>
<span class="sourceLineNo">3265</span>                    __entryParser = __parserFactory.createFileEntryParser(systemType);<a name="line.3265"></a>
<span class="sourceLineNo">3266</span>                    __entryParserKey = systemType;<a name="line.3266"></a>
<span class="sourceLineNo">3267</span>                }<a name="line.3267"></a>
<span class="sourceLineNo">3268</span>            }<a name="line.3268"></a>
<span class="sourceLineNo">3269</span>        }<a name="line.3269"></a>
<span class="sourceLineNo">3270</span><a name="line.3270"></a>
<span class="sourceLineNo">3271</span>        return initiateListParsing(__entryParser, pathname);<a name="line.3271"></a>
<span class="sourceLineNo">3272</span><a name="line.3272"></a>
<span class="sourceLineNo">3273</span>    }<a name="line.3273"></a>
<span class="sourceLineNo">3274</span><a name="line.3274"></a>
<span class="sourceLineNo">3275</span>    /**<a name="line.3275"></a>
<span class="sourceLineNo">3276</span>     * private method through which all listFiles() and<a name="line.3276"></a>
<span class="sourceLineNo">3277</span>     * initiateListParsing methods pass once a parser is determined.<a name="line.3277"></a>
<span class="sourceLineNo">3278</span>     *<a name="line.3278"></a>
<span class="sourceLineNo">3279</span>     * @exception FTPConnectionClosedException<a name="line.3279"></a>
<span class="sourceLineNo">3280</span>     *                   If the FTP server prematurely closes the connection as a result<a name="line.3280"></a>
<span class="sourceLineNo">3281</span>     *                   of the client being idle or some other reason causing the server<a name="line.3281"></a>
<span class="sourceLineNo">3282</span>     *                   to send FTP reply code 421.  This exception may be caught either<a name="line.3282"></a>
<span class="sourceLineNo">3283</span>     *                   as an IOException or independently as itself.<a name="line.3283"></a>
<span class="sourceLineNo">3284</span>     * @exception IOException<a name="line.3284"></a>
<span class="sourceLineNo">3285</span>     *                   If an I/O error occurs while either sending a<a name="line.3285"></a>
<span class="sourceLineNo">3286</span>     *                   command to the server or receiving a reply from the server.<a name="line.3286"></a>
<span class="sourceLineNo">3287</span>     * @see FTPListParseEngine<a name="line.3287"></a>
<span class="sourceLineNo">3288</span>     */<a name="line.3288"></a>
<span class="sourceLineNo">3289</span>    private FTPListParseEngine initiateListParsing(<a name="line.3289"></a>
<span class="sourceLineNo">3290</span>            FTPFileEntryParser parser, String pathname)<a name="line.3290"></a>
<span class="sourceLineNo">3291</span>    throws IOException<a name="line.3291"></a>
<span class="sourceLineNo">3292</span>    {<a name="line.3292"></a>
<span class="sourceLineNo">3293</span>        Socket socket = _openDataConnection_(FTPCmd.LIST, getListArguments(pathname));<a name="line.3293"></a>
<span class="sourceLineNo">3294</span><a name="line.3294"></a>
<span class="sourceLineNo">3295</span>        FTPListParseEngine engine = new FTPListParseEngine(parser);<a name="line.3295"></a>
<span class="sourceLineNo">3296</span>        if (socket == null)<a name="line.3296"></a>
<span class="sourceLineNo">3297</span>        {<a name="line.3297"></a>
<span class="sourceLineNo">3298</span>            return engine;<a name="line.3298"></a>
<span class="sourceLineNo">3299</span>        }<a name="line.3299"></a>
<span class="sourceLineNo">3300</span><a name="line.3300"></a>
<span class="sourceLineNo">3301</span>        try {<a name="line.3301"></a>
<span class="sourceLineNo">3302</span>            engine.readServerList(socket.getInputStream(), getControlEncoding());<a name="line.3302"></a>
<span class="sourceLineNo">3303</span>        }<a name="line.3303"></a>
<span class="sourceLineNo">3304</span>        finally {<a name="line.3304"></a>
<span class="sourceLineNo">3305</span>            Util.closeQuietly(socket);<a name="line.3305"></a>
<span class="sourceLineNo">3306</span>        }<a name="line.3306"></a>
<span class="sourceLineNo">3307</span><a name="line.3307"></a>
<span class="sourceLineNo">3308</span>        completePendingCommand();<a name="line.3308"></a>
<span class="sourceLineNo">3309</span>        return engine;<a name="line.3309"></a>
<span class="sourceLineNo">3310</span>    }<a name="line.3310"></a>
<span class="sourceLineNo">3311</span><a name="line.3311"></a>
<span class="sourceLineNo">3312</span>    /**<a name="line.3312"></a>
<span class="sourceLineNo">3313</span>     * Initiate list parsing for MLSD listings.<a name="line.3313"></a>
<span class="sourceLineNo">3314</span>     *<a name="line.3314"></a>
<span class="sourceLineNo">3315</span>     * @param pathname<a name="line.3315"></a>
<span class="sourceLineNo">3316</span>     * @return the engine<a name="line.3316"></a>
<span class="sourceLineNo">3317</span>     * @throws IOException<a name="line.3317"></a>
<span class="sourceLineNo">3318</span>     */<a name="line.3318"></a>
<span class="sourceLineNo">3319</span>    private FTPListParseEngine initiateMListParsing(String pathname) throws IOException<a name="line.3319"></a>
<span class="sourceLineNo">3320</span>    {<a name="line.3320"></a>
<span class="sourceLineNo">3321</span>        Socket socket = _openDataConnection_(FTPCmd.MLSD, pathname);<a name="line.3321"></a>
<span class="sourceLineNo">3322</span>        FTPListParseEngine engine = new FTPListParseEngine(MLSxEntryParser.getInstance());<a name="line.3322"></a>
<span class="sourceLineNo">3323</span>        if (socket == null)<a name="line.3323"></a>
<span class="sourceLineNo">3324</span>        {<a name="line.3324"></a>
<span class="sourceLineNo">3325</span>            return engine;<a name="line.3325"></a>
<span class="sourceLineNo">3326</span>        }<a name="line.3326"></a>
<span class="sourceLineNo">3327</span><a name="line.3327"></a>
<span class="sourceLineNo">3328</span>        try {<a name="line.3328"></a>
<span class="sourceLineNo">3329</span>            engine.readServerList(socket.getInputStream(), getControlEncoding());<a name="line.3329"></a>
<span class="sourceLineNo">3330</span>        }<a name="line.3330"></a>
<span class="sourceLineNo">3331</span>        finally {<a name="line.3331"></a>
<span class="sourceLineNo">3332</span>            Util.closeQuietly(socket);<a name="line.3332"></a>
<span class="sourceLineNo">3333</span>            completePendingCommand();<a name="line.3333"></a>
<span class="sourceLineNo">3334</span>        }<a name="line.3334"></a>
<span class="sourceLineNo">3335</span>        return engine;<a name="line.3335"></a>
<span class="sourceLineNo">3336</span>    }<a name="line.3336"></a>
<span class="sourceLineNo">3337</span><a name="line.3337"></a>
<span class="sourceLineNo">3338</span>    /**<a name="line.3338"></a>
<span class="sourceLineNo">3339</span>     * @since 2.0<a name="line.3339"></a>
<span class="sourceLineNo">3340</span>     */<a name="line.3340"></a>
<span class="sourceLineNo">3341</span>    protected String getListArguments(String pathname) {<a name="line.3341"></a>
<span class="sourceLineNo">3342</span>        if (getListHiddenFiles())<a name="line.3342"></a>
<span class="sourceLineNo">3343</span>        {<a name="line.3343"></a>
<span class="sourceLineNo">3344</span>            if (pathname != null)<a name="line.3344"></a>
<span class="sourceLineNo">3345</span>            {<a name="line.3345"></a>
<span class="sourceLineNo">3346</span>                StringBuilder sb = new StringBuilder(pathname.length() + 3);<a name="line.3346"></a>
<span class="sourceLineNo">3347</span>                sb.append("-a ");<a name="line.3347"></a>
<span class="sourceLineNo">3348</span>                sb.append(pathname);<a name="line.3348"></a>
<span class="sourceLineNo">3349</span>                return sb.toString();<a name="line.3349"></a>
<span class="sourceLineNo">3350</span>            }<a name="line.3350"></a>
<span class="sourceLineNo">3351</span>            else<a name="line.3351"></a>
<span class="sourceLineNo">3352</span>            {<a name="line.3352"></a>
<span class="sourceLineNo">3353</span>                return "-a";<a name="line.3353"></a>
<span class="sourceLineNo">3354</span>            }<a name="line.3354"></a>
<span class="sourceLineNo">3355</span>        }<a name="line.3355"></a>
<span class="sourceLineNo">3356</span><a name="line.3356"></a>
<span class="sourceLineNo">3357</span>        return pathname;<a name="line.3357"></a>
<span class="sourceLineNo">3358</span>    }<a name="line.3358"></a>
<span class="sourceLineNo">3359</span><a name="line.3359"></a>
<span class="sourceLineNo">3360</span><a name="line.3360"></a>
<span class="sourceLineNo">3361</span>    /**<a name="line.3361"></a>
<span class="sourceLineNo">3362</span>     * Issue the FTP STAT command to the server.<a name="line.3362"></a>
<span class="sourceLineNo">3363</span>     * &lt;p&gt;<a name="line.3363"></a>
<span class="sourceLineNo">3364</span>     * @return The status information returned by the server.<a name="line.3364"></a>
<span class="sourceLineNo">3365</span>     * @exception FTPConnectionClosedException<a name="line.3365"></a>
<span class="sourceLineNo">3366</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.3366"></a>
<span class="sourceLineNo">3367</span>     *      of the client being idle or some other reason causing the server<a name="line.3367"></a>
<span class="sourceLineNo">3368</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.3368"></a>
<span class="sourceLineNo">3369</span>     *      as an IOException or independently as itself.<a name="line.3369"></a>
<span class="sourceLineNo">3370</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.3370"></a>
<span class="sourceLineNo">3371</span>     *      command to the server or receiving a reply from the server.<a name="line.3371"></a>
<span class="sourceLineNo">3372</span>     */<a name="line.3372"></a>
<span class="sourceLineNo">3373</span>    public String getStatus() throws IOException<a name="line.3373"></a>
<span class="sourceLineNo">3374</span>    {<a name="line.3374"></a>
<span class="sourceLineNo">3375</span>        if (FTPReply.isPositiveCompletion(stat())) {<a name="line.3375"></a>
<span class="sourceLineNo">3376</span>            return getReplyString();<a name="line.3376"></a>
<span class="sourceLineNo">3377</span>        }<a name="line.3377"></a>
<span class="sourceLineNo">3378</span>        return null;<a name="line.3378"></a>
<span class="sourceLineNo">3379</span>    }<a name="line.3379"></a>
<span class="sourceLineNo">3380</span><a name="line.3380"></a>
<span class="sourceLineNo">3381</span><a name="line.3381"></a>
<span class="sourceLineNo">3382</span>    /**<a name="line.3382"></a>
<span class="sourceLineNo">3383</span>     * Issue the FTP STAT command to the server for a given pathname.  This<a name="line.3383"></a>
<span class="sourceLineNo">3384</span>     * should produce a listing of the file or directory.<a name="line.3384"></a>
<span class="sourceLineNo">3385</span>     * &lt;p&gt;<a name="line.3385"></a>
<span class="sourceLineNo">3386</span>     * @return The status information returned by the server.<a name="line.3386"></a>
<span class="sourceLineNo">3387</span>     * @exception FTPConnectionClosedException<a name="line.3387"></a>
<span class="sourceLineNo">3388</span>     *      If the FTP server prematurely closes the connection as a result<a name="line.3388"></a>
<span class="sourceLineNo">3389</span>     *      of the client being idle or some other reason causing the server<a name="line.3389"></a>
<span class="sourceLineNo">3390</span>     *      to send FTP reply code 421.  This exception may be caught either<a name="line.3390"></a>
<span class="sourceLineNo">3391</span>     *      as an IOException or independently as itself.<a name="line.3391"></a>
<span class="sourceLineNo">3392</span>     * @exception IOException  If an I/O error occurs while either sending a<a name="line.3392"></a>
<span class="sourceLineNo">3393</span>     *      command to the server or receiving a reply from the server.<a name="line.3393"></a>
<span class="sourceLineNo">3394</span>     */<a name="line.3394"></a>
<span class="sourceLineNo">3395</span>    public String getStatus(String pathname) throws IOException<a name="line.3395"></a>
<span class="sourceLineNo">3396</span>    {<a name="line.3396"></a>
<span class="sourceLineNo">3397</span>        if (FTPReply.isPositiveCompletion(stat(pathname))) {<a name="line.3397"></a>
<span class="sourceLineNo">3398</span>            return getReplyString();<a name="line.3398"></a>
<span class="sourceLineNo">3399</span>        }<a name="line.3399"></a>
<span class="sourceLineNo">3400</span>        return null;<a name="line.3400"></a>
<span class="sourceLineNo">3401</span>    }<a name="line.3401"></a>
<span class="sourceLineNo">3402</span><a name="line.3402"></a>
<span class="sourceLineNo">3403</span><a name="line.3403"></a>
<span class="sourceLineNo">3404</span>    /**<a name="line.3404"></a>
<span class="sourceLineNo">3405</span>     * Issue the FTP MDTM command (not supported by all servers to retrieve the last<a name="line.3405"></a>
<span class="sourceLineNo">3406</span>     * modification time of a file. The modification string should be in the<a name="line.3406"></a>
<span class="sourceLineNo">3407</span>     * ISO 3077 form "YYYYMMDDhhmmss(.xxx)?". The timestamp represented should also be in<a name="line.3407"></a>
<span class="sourceLineNo">3408</span>     * GMT, but not all FTP servers honour this.<a name="line.3408"></a>
<span class="sourceLineNo">3409</span>     *<a name="line.3409"></a>
<span class="sourceLineNo">3410</span>     * @param pathname The file path to query.<a name="line.3410"></a>
<span class="sourceLineNo">3411</span>     * @return A string representing the last file modification time in &lt;code&gt;YYYYMMDDhhmmss&lt;/code&gt; format.<a name="line.3411"></a>
<span class="sourceLineNo">3412</span>     * @throws IOException if an I/O error occurs.<a name="line.3412"></a>
<span class="sourceLineNo">3413</span>     * @since 2.0<a name="line.3413"></a>
<span class="sourceLineNo">3414</span>     */<a name="line.3414"></a>
<span class="sourceLineNo">3415</span>    public String getModificationTime(String pathname) throws IOException {<a name="line.3415"></a>
<span class="sourceLineNo">3416</span>        if (FTPReply.isPositiveCompletion(mdtm(pathname))) {<a name="line.3416"></a>
<span class="sourceLineNo">3417</span>            return getReplyString();<a name="line.3417"></a>
<span class="sourceLineNo">3418</span>        }<a name="line.3418"></a>
<span class="sourceLineNo">3419</span>        return null;<a name="line.3419"></a>
<span class="sourceLineNo">3420</span>    }<a name="line.3420"></a>
<span class="sourceLineNo">3421</span><a name="line.3421"></a>
<span class="sourceLineNo">3422</span><a name="line.3422"></a>
<span class="sourceLineNo">3423</span>    /**<a name="line.3423"></a>
<span class="sourceLineNo">3424</span>     * Issue the FTP MFMT command (not supported by all servers) which sets the last<a name="line.3424"></a>
<span class="sourceLineNo">3425</span>     * modified time of a file.<a name="line.3425"></a>
<span class="sourceLineNo">3426</span>     *<a name="line.3426"></a>
<span class="sourceLineNo">3427</span>     * The timestamp should be in the form &lt;code&gt;YYYYMMDDhhmmss&lt;/code&gt;. It should also<a name="line.3427"></a>
<span class="sourceLineNo">3428</span>     * be in GMT, but not all servers honour this.<a name="line.3428"></a>
<span class="sourceLineNo">3429</span>     *<a name="line.3429"></a>
<span class="sourceLineNo">3430</span>     * An FTP server would indicate its support of this feature by including "MFMT"<a name="line.3430"></a>
<span class="sourceLineNo">3431</span>     * in its response to the FEAT command, which may be retrieved by FTPClient.features()<a name="line.3431"></a>
<span class="sourceLineNo">3432</span>     *<a name="line.3432"></a>
<span class="sourceLineNo">3433</span>     * @param pathname The file path for which last modified time is to be changed.<a name="line.3433"></a>
<span class="sourceLineNo">3434</span>     * @param timeval The timestamp to set to, in &lt;code&gt;YYYYMMDDhhmmss&lt;/code&gt; format.<a name="line.3434"></a>
<span class="sourceLineNo">3435</span>     * @return true if successfully set, false if not<a name="line.3435"></a>
<span class="sourceLineNo">3436</span>     * @throws IOException if an I/O error occurs.<a name="line.3436"></a>
<span class="sourceLineNo">3437</span>     * @since 2.2<a name="line.3437"></a>
<span class="sourceLineNo">3438</span>     * @see &lt;a href="http://tools.ietf.org/html/draft-somers-ftp-mfxx-04"&gt;http://tools.ietf.org/html/draft-somers-ftp-mfxx-04&lt;/a&gt;<a name="line.3438"></a>
<span class="sourceLineNo">3439</span>     */<a name="line.3439"></a>
<span class="sourceLineNo">3440</span>    public boolean setModificationTime(String pathname, String timeval) throws IOException {<a name="line.3440"></a>
<span class="sourceLineNo">3441</span>        return (FTPReply.isPositiveCompletion(mfmt(pathname, timeval)));<a name="line.3441"></a>
<span class="sourceLineNo">3442</span>    }<a name="line.3442"></a>
<span class="sourceLineNo">3443</span><a name="line.3443"></a>
<span class="sourceLineNo">3444</span><a name="line.3444"></a>
<span class="sourceLineNo">3445</span>    /**<a name="line.3445"></a>
<span class="sourceLineNo">3446</span>     * Set the internal buffer size for buffered data streams.<a name="line.3446"></a>
<span class="sourceLineNo">3447</span>     *<a name="line.3447"></a>
<span class="sourceLineNo">3448</span>     * @param bufSize The size of the buffer. Use a non-positive value to use the default.<a name="line.3448"></a>
<span class="sourceLineNo">3449</span>     */<a name="line.3449"></a>
<span class="sourceLineNo">3450</span>    public void setBufferSize(int bufSize) {<a name="line.3450"></a>
<span class="sourceLineNo">3451</span>        __bufferSize = bufSize;<a name="line.3451"></a>
<span class="sourceLineNo">3452</span>    }<a name="line.3452"></a>
<span class="sourceLineNo">3453</span><a name="line.3453"></a>
<span class="sourceLineNo">3454</span>    /**<a name="line.3454"></a>
<span class="sourceLineNo">3455</span>     * Retrieve the current internal buffer size for buffered data streams.<a name="line.3455"></a>
<span class="sourceLineNo">3456</span>     * @return The current buffer size.<a name="line.3456"></a>
<span class="sourceLineNo">3457</span>     */<a name="line.3457"></a>
<span class="sourceLineNo">3458</span>    public int getBufferSize() {<a name="line.3458"></a>
<span class="sourceLineNo">3459</span>        return __bufferSize;<a name="line.3459"></a>
<span class="sourceLineNo">3460</span>    }<a name="line.3460"></a>
<span class="sourceLineNo">3461</span><a name="line.3461"></a>
<span class="sourceLineNo">3462</span>    /**<a name="line.3462"></a>
<span class="sourceLineNo">3463</span>     * Sets the value to be used for the data socket SO_SNDBUF option.<a name="line.3463"></a>
<span class="sourceLineNo">3464</span>     * If the value is positive, the option will be set when the data socket has been created.<a name="line.3464"></a>
<span class="sourceLineNo">3465</span>     *<a name="line.3465"></a>
<span class="sourceLineNo">3466</span>     * @param bufSize The size of the buffer, zero or negative means the value is ignored.<a name="line.3466"></a>
<span class="sourceLineNo">3467</span>      * @since 3.3<a name="line.3467"></a>
<span class="sourceLineNo">3468</span>    */<a name="line.3468"></a>
<span class="sourceLineNo">3469</span>    public void setSendDataSocketBufferSize(int bufSize) {<a name="line.3469"></a>
<span class="sourceLineNo">3470</span>        __sendDataSocketBufferSize = bufSize;<a name="line.3470"></a>
<span class="sourceLineNo">3471</span>    }<a name="line.3471"></a>
<span class="sourceLineNo">3472</span><a name="line.3472"></a>
<span class="sourceLineNo">3473</span>    /**<a name="line.3473"></a>
<span class="sourceLineNo">3474</span>     * Retrieve the value to be used for the data socket SO_SNDBUF option.<a name="line.3474"></a>
<span class="sourceLineNo">3475</span>     * @return The current buffer size.<a name="line.3475"></a>
<span class="sourceLineNo">3476</span>     * @since 3.3<a name="line.3476"></a>
<span class="sourceLineNo">3477</span>     */<a name="line.3477"></a>
<span class="sourceLineNo">3478</span>    public int getSendDataSocketBufferSize() {<a name="line.3478"></a>
<span class="sourceLineNo">3479</span>        return __sendDataSocketBufferSize;<a name="line.3479"></a>
<span class="sourceLineNo">3480</span>    }<a name="line.3480"></a>
<span class="sourceLineNo">3481</span><a name="line.3481"></a>
<span class="sourceLineNo">3482</span>    /**<a name="line.3482"></a>
<span class="sourceLineNo">3483</span>     * Sets the value to be used for the data socket SO_RCVBUF option.<a name="line.3483"></a>
<span class="sourceLineNo">3484</span>     * If the value is positive, the option will be set when the data socket has been created.<a name="line.3484"></a>
<span class="sourceLineNo">3485</span>     *<a name="line.3485"></a>
<span class="sourceLineNo">3486</span>     * @param bufSize The size of the buffer, zero or negative means the value is ignored.<a name="line.3486"></a>
<span class="sourceLineNo">3487</span>     * @since 3.3<a name="line.3487"></a>
<span class="sourceLineNo">3488</span>     */<a name="line.3488"></a>
<span class="sourceLineNo">3489</span>    public void setReceieveDataSocketBufferSize(int bufSize) {<a name="line.3489"></a>
<span class="sourceLineNo">3490</span>        __receiveDataSocketBufferSize = bufSize;<a name="line.3490"></a>
<span class="sourceLineNo">3491</span>    }<a name="line.3491"></a>
<span class="sourceLineNo">3492</span><a name="line.3492"></a>
<span class="sourceLineNo">3493</span>    /**<a name="line.3493"></a>
<span class="sourceLineNo">3494</span>     * Retrieve the value to be used for the data socket SO_RCVBUF option.<a name="line.3494"></a>
<span class="sourceLineNo">3495</span>     * @return The current buffer size.<a name="line.3495"></a>
<span class="sourceLineNo">3496</span>     * @since 3.3<a name="line.3496"></a>
<span class="sourceLineNo">3497</span>     */<a name="line.3497"></a>
<span class="sourceLineNo">3498</span>    public int getReceiveDataSocketBufferSize() {<a name="line.3498"></a>
<span class="sourceLineNo">3499</span>        return __receiveDataSocketBufferSize;<a name="line.3499"></a>
<span class="sourceLineNo">3500</span>    }<a name="line.3500"></a>
<span class="sourceLineNo">3501</span><a name="line.3501"></a>
<span class="sourceLineNo">3502</span>    /**<a name="line.3502"></a>
<span class="sourceLineNo">3503</span>     * Implementation of the {@link Configurable Configurable} interface.<a name="line.3503"></a>
<span class="sourceLineNo">3504</span>     * In the case of this class, configuring merely makes the config object available for the<a name="line.3504"></a>
<span class="sourceLineNo">3505</span>     * factory methods that construct parsers.<a name="line.3505"></a>
<span class="sourceLineNo">3506</span>     * @param config {@link FTPClientConfig FTPClientConfig} object used to<a name="line.3506"></a>
<span class="sourceLineNo">3507</span>     * provide non-standard configurations to the parser.<a name="line.3507"></a>
<span class="sourceLineNo">3508</span>     * @since 1.4<a name="line.3508"></a>
<span class="sourceLineNo">3509</span>     */<a name="line.3509"></a>
<span class="sourceLineNo">3510</span>//    @Override<a name="line.3510"></a>
<span class="sourceLineNo">3511</span>    public void configure(FTPClientConfig config) {<a name="line.3511"></a>
<span class="sourceLineNo">3512</span>        this.__configuration = config;<a name="line.3512"></a>
<span class="sourceLineNo">3513</span>    }<a name="line.3513"></a>
<span class="sourceLineNo">3514</span><a name="line.3514"></a>
<span class="sourceLineNo">3515</span>    /**<a name="line.3515"></a>
<span class="sourceLineNo">3516</span>     * You can set this to true if you would like to get hidden files when {@link #listFiles} too.<a name="line.3516"></a>
<span class="sourceLineNo">3517</span>     * A &lt;code&gt;LIST -a&lt;/code&gt; will be issued to the ftp server.<a name="line.3517"></a>
<span class="sourceLineNo">3518</span>     * It depends on your ftp server if you need to call this method, also dont expect to get rid<a name="line.3518"></a>
<span class="sourceLineNo">3519</span>     * of hidden files if you call this method with "false".<a name="line.3519"></a>
<span class="sourceLineNo">3520</span>     *<a name="line.3520"></a>
<span class="sourceLineNo">3521</span>     * @param listHiddenFiles true if hidden files should be listed<a name="line.3521"></a>
<span class="sourceLineNo">3522</span>     * @since 2.0<a name="line.3522"></a>
<span class="sourceLineNo">3523</span>     */<a name="line.3523"></a>
<span class="sourceLineNo">3524</span>    public void setListHiddenFiles(boolean listHiddenFiles) {<a name="line.3524"></a>
<span class="sourceLineNo">3525</span>        this.__listHiddenFiles = listHiddenFiles;<a name="line.3525"></a>
<span class="sourceLineNo">3526</span>    }<a name="line.3526"></a>
<span class="sourceLineNo">3527</span><a name="line.3527"></a>
<span class="sourceLineNo">3528</span>    /**<a name="line.3528"></a>
<span class="sourceLineNo">3529</span>     * @see #setListHiddenFiles(boolean)<a name="line.3529"></a>
<span class="sourceLineNo">3530</span>     * @return the current state<a name="line.3530"></a>
<span class="sourceLineNo">3531</span>     * @since 2.0<a name="line.3531"></a>
<span class="sourceLineNo">3532</span>     */<a name="line.3532"></a>
<span class="sourceLineNo">3533</span>    public boolean getListHiddenFiles() {<a name="line.3533"></a>
<span class="sourceLineNo">3534</span>        return this.__listHiddenFiles;<a name="line.3534"></a>
<span class="sourceLineNo">3535</span>    }<a name="line.3535"></a>
<span class="sourceLineNo">3536</span><a name="line.3536"></a>
<span class="sourceLineNo">3537</span>    /**<a name="line.3537"></a>
<span class="sourceLineNo">3538</span>     * Whether should attempt to use EPSV with IPv4.<a name="line.3538"></a>
<span class="sourceLineNo">3539</span>     * Default (if not set) is &lt;code&gt;false&lt;/code&gt;<a name="line.3539"></a>
<span class="sourceLineNo">3540</span>     * @return true if should attempt EPSV<a name="line.3540"></a>
<span class="sourceLineNo">3541</span>     * @since 2.2<a name="line.3541"></a>
<span class="sourceLineNo">3542</span>     */<a name="line.3542"></a>
<span class="sourceLineNo">3543</span>    public boolean isUseEPSVwithIPv4() {<a name="line.3543"></a>
<span class="sourceLineNo">3544</span>        return __useEPSVwithIPv4;<a name="line.3544"></a>
<span class="sourceLineNo">3545</span>    }<a name="line.3545"></a>
<span class="sourceLineNo">3546</span><a name="line.3546"></a>
<span class="sourceLineNo">3547</span><a name="line.3547"></a>
<span class="sourceLineNo">3548</span>    /**<a name="line.3548"></a>
<span class="sourceLineNo">3549</span>     * Set whether to use EPSV with IPv4.<a name="line.3549"></a>
<span class="sourceLineNo">3550</span>     * Might be worth enabling in some circumstances.<a name="line.3550"></a>
<span class="sourceLineNo">3551</span>     *<a name="line.3551"></a>
<span class="sourceLineNo">3552</span>     * For example, when using IPv4 with NAT it<a name="line.3552"></a>
<span class="sourceLineNo">3553</span>     * may work with some rare configurations.<a name="line.3553"></a>
<span class="sourceLineNo">3554</span>     * E.g. if FTP server has a static PASV address (external network)<a name="line.3554"></a>
<span class="sourceLineNo">3555</span>     * and the client is coming from another internal network.<a name="line.3555"></a>
<span class="sourceLineNo">3556</span>     * In that case the data connection after PASV command would fail,<a name="line.3556"></a>
<span class="sourceLineNo">3557</span>     * while EPSV would make the client succeed by taking just the port.<a name="line.3557"></a>
<span class="sourceLineNo">3558</span>     *<a name="line.3558"></a>
<span class="sourceLineNo">3559</span>     * @param selected value to set.<a name="line.3559"></a>
<span class="sourceLineNo">3560</span>     * @since 2.2<a name="line.3560"></a>
<span class="sourceLineNo">3561</span>     */<a name="line.3561"></a>
<span class="sourceLineNo">3562</span>    public void setUseEPSVwithIPv4(boolean selected) {<a name="line.3562"></a>
<span class="sourceLineNo">3563</span>        this.__useEPSVwithIPv4 = selected;<a name="line.3563"></a>
<span class="sourceLineNo">3564</span>    }<a name="line.3564"></a>
<span class="sourceLineNo">3565</span><a name="line.3565"></a>
<span class="sourceLineNo">3566</span>    /**<a name="line.3566"></a>
<span class="sourceLineNo">3567</span>     * Set the listener to be used when performing store/retrieve operations.<a name="line.3567"></a>
<span class="sourceLineNo">3568</span>     * The default value (if not set) is {@code null}.<a name="line.3568"></a>
<span class="sourceLineNo">3569</span>     *<a name="line.3569"></a>
<span class="sourceLineNo">3570</span>     * @param listener to be used, may be {@code null} to disable<a name="line.3570"></a>
<span class="sourceLineNo">3571</span>     * @since 3.0<a name="line.3571"></a>
<span class="sourceLineNo">3572</span>     */<a name="line.3572"></a>
<span class="sourceLineNo">3573</span>    public void setCopyStreamListener(CopyStreamListener listener){<a name="line.3573"></a>
<span class="sourceLineNo">3574</span>        __copyStreamListener = listener;<a name="line.3574"></a>
<span class="sourceLineNo">3575</span>    }<a name="line.3575"></a>
<span class="sourceLineNo">3576</span><a name="line.3576"></a>
<span class="sourceLineNo">3577</span>    /**<a name="line.3577"></a>
<span class="sourceLineNo">3578</span>     * Obtain the currently active listener.<a name="line.3578"></a>
<span class="sourceLineNo">3579</span>     *<a name="line.3579"></a>
<span class="sourceLineNo">3580</span>     * @return the listener, may be {@code null}<a name="line.3580"></a>
<span class="sourceLineNo">3581</span>     * @since 3.0<a name="line.3581"></a>
<span class="sourceLineNo">3582</span>     */<a name="line.3582"></a>
<span class="sourceLineNo">3583</span>    public CopyStreamListener getCopyStreamListener(){<a name="line.3583"></a>
<span class="sourceLineNo">3584</span>        return __copyStreamListener;<a name="line.3584"></a>
<span class="sourceLineNo">3585</span>    }<a name="line.3585"></a>
<span class="sourceLineNo">3586</span><a name="line.3586"></a>
<span class="sourceLineNo">3587</span>    /**<a name="line.3587"></a>
<span class="sourceLineNo">3588</span>     * Set the time to wait between sending control connection keepalive messages<a name="line.3588"></a>
<span class="sourceLineNo">3589</span>     * when processing file upload or download.<a name="line.3589"></a>
<span class="sourceLineNo">3590</span>     *<a name="line.3590"></a>
<span class="sourceLineNo">3591</span>     * @param controlIdle the wait (in secs) between keepalive messages. Zero (or less) disables.<a name="line.3591"></a>
<span class="sourceLineNo">3592</span>     * @since 3.0<a name="line.3592"></a>
<span class="sourceLineNo">3593</span>     * @see #setControlKeepAliveReplyTimeout(int)<a name="line.3593"></a>
<span class="sourceLineNo">3594</span>     */<a name="line.3594"></a>
<span class="sourceLineNo">3595</span>    public void setControlKeepAliveTimeout(long controlIdle){<a name="line.3595"></a>
<span class="sourceLineNo">3596</span>        __controlKeepAliveTimeout = controlIdle * 1000;<a name="line.3596"></a>
<span class="sourceLineNo">3597</span>    }<a name="line.3597"></a>
<span class="sourceLineNo">3598</span><a name="line.3598"></a>
<span class="sourceLineNo">3599</span>    /**<a name="line.3599"></a>
<span class="sourceLineNo">3600</span>     * Get the time to wait between sending control connection keepalive messages.<a name="line.3600"></a>
<span class="sourceLineNo">3601</span>     * @return the number of seconds between keepalive messages.<a name="line.3601"></a>
<span class="sourceLineNo">3602</span>     * @since 3.0<a name="line.3602"></a>
<span class="sourceLineNo">3603</span>     */<a name="line.3603"></a>
<span class="sourceLineNo">3604</span>    public long getControlKeepAliveTimeout() {<a name="line.3604"></a>
<span class="sourceLineNo">3605</span>        return __controlKeepAliveTimeout / 1000;<a name="line.3605"></a>
<span class="sourceLineNo">3606</span>    }<a name="line.3606"></a>
<span class="sourceLineNo">3607</span><a name="line.3607"></a>
<span class="sourceLineNo">3608</span>    /**<a name="line.3608"></a>
<span class="sourceLineNo">3609</span>     * Set how long to wait for control keep-alive message replies.<a name="line.3609"></a>
<span class="sourceLineNo">3610</span>     *<a name="line.3610"></a>
<span class="sourceLineNo">3611</span>     * @param timeout number of milliseconds to wait (defaults to 1000)<a name="line.3611"></a>
<span class="sourceLineNo">3612</span>     * @since 3.0<a name="line.3612"></a>
<span class="sourceLineNo">3613</span>     * @see #setControlKeepAliveTimeout(long)<a name="line.3613"></a>
<span class="sourceLineNo">3614</span>     */<a name="line.3614"></a>
<span class="sourceLineNo">3615</span>    public void setControlKeepAliveReplyTimeout(int timeout) {<a name="line.3615"></a>
<span class="sourceLineNo">3616</span>        __controlKeepAliveReplyTimeout = timeout;<a name="line.3616"></a>
<span class="sourceLineNo">3617</span>    }<a name="line.3617"></a>
<span class="sourceLineNo">3618</span><a name="line.3618"></a>
<span class="sourceLineNo">3619</span>    /**<a name="line.3619"></a>
<span class="sourceLineNo">3620</span>     * Get how long to wait for control keep-alive message replies.<a name="line.3620"></a>
<span class="sourceLineNo">3621</span>     * @since 3.0<a name="line.3621"></a>
<span class="sourceLineNo">3622</span>     */<a name="line.3622"></a>
<span class="sourceLineNo">3623</span>    public int getControlKeepAliveReplyTimeout() {<a name="line.3623"></a>
<span class="sourceLineNo">3624</span>        return __controlKeepAliveReplyTimeout;<a name="line.3624"></a>
<span class="sourceLineNo">3625</span>    }<a name="line.3625"></a>
<span class="sourceLineNo">3626</span><a name="line.3626"></a>
<span class="sourceLineNo">3627</span>    /**<a name="line.3627"></a>
<span class="sourceLineNo">3628</span>     * Enable or disable passive mode NAT workaround.<a name="line.3628"></a>
<span class="sourceLineNo">3629</span>     * If enabled, a site-local PASV mode reply address will be replaced with the<a name="line.3629"></a>
<span class="sourceLineNo">3630</span>     * remote host address to which the PASV mode request was sent<a name="line.3630"></a>
<span class="sourceLineNo">3631</span>     * (unless that is also a site local address).<a name="line.3631"></a>
<span class="sourceLineNo">3632</span>     * This gets around the problem that some NAT boxes may change the<a name="line.3632"></a>
<span class="sourceLineNo">3633</span>     * reply.<a name="line.3633"></a>
<span class="sourceLineNo">3634</span>     *<a name="line.3634"></a>
<span class="sourceLineNo">3635</span>     * The default is true, i.e. site-local replies are replaced.<a name="line.3635"></a>
<span class="sourceLineNo">3636</span>     * @param enabled true to enable replacing internal IP's in passive<a name="line.3636"></a>
<span class="sourceLineNo">3637</span>     * mode.<a name="line.3637"></a>
<span class="sourceLineNo">3638</span>     */<a name="line.3638"></a>
<span class="sourceLineNo">3639</span>    public void setPassiveNatWorkaround(boolean enabled) {<a name="line.3639"></a>
<span class="sourceLineNo">3640</span>        this.__passiveNatWorkaround = enabled;<a name="line.3640"></a>
<span class="sourceLineNo">3641</span>    }<a name="line.3641"></a>
<span class="sourceLineNo">3642</span><a name="line.3642"></a>
<span class="sourceLineNo">3643</span>    private OutputStream getBufferedOutputStream(OutputStream outputStream) {<a name="line.3643"></a>
<span class="sourceLineNo">3644</span>        if (__bufferSize &gt; 0) {<a name="line.3644"></a>
<span class="sourceLineNo">3645</span>            return new BufferedOutputStream(outputStream, __bufferSize);<a name="line.3645"></a>
<span class="sourceLineNo">3646</span>        }<a name="line.3646"></a>
<span class="sourceLineNo">3647</span>        return new BufferedOutputStream(outputStream);<a name="line.3647"></a>
<span class="sourceLineNo">3648</span>    }<a name="line.3648"></a>
<span class="sourceLineNo">3649</span><a name="line.3649"></a>
<span class="sourceLineNo">3650</span>    private InputStream getBufferedInputStream(InputStream inputStream) {<a name="line.3650"></a>
<span class="sourceLineNo">3651</span>        if (__bufferSize &gt; 0) {<a name="line.3651"></a>
<span class="sourceLineNo">3652</span>            return new BufferedInputStream(inputStream, __bufferSize);<a name="line.3652"></a>
<span class="sourceLineNo">3653</span>        }<a name="line.3653"></a>
<span class="sourceLineNo">3654</span>        return new BufferedInputStream(inputStream);<a name="line.3654"></a>
<span class="sourceLineNo">3655</span>    }<a name="line.3655"></a>
<span class="sourceLineNo">3656</span><a name="line.3656"></a>
<span class="sourceLineNo">3657</span>    // @since 3.0<a name="line.3657"></a>
<span class="sourceLineNo">3658</span>    private static class CSL implements CopyStreamListener {<a name="line.3658"></a>
<span class="sourceLineNo">3659</span><a name="line.3659"></a>
<span class="sourceLineNo">3660</span>        private final FTPClient parent;<a name="line.3660"></a>
<span class="sourceLineNo">3661</span>        private final long idle;<a name="line.3661"></a>
<span class="sourceLineNo">3662</span>        private final int currentSoTimeout;<a name="line.3662"></a>
<span class="sourceLineNo">3663</span><a name="line.3663"></a>
<span class="sourceLineNo">3664</span>        private long time = System.currentTimeMillis();<a name="line.3664"></a>
<span class="sourceLineNo">3665</span>        private int notAcked;<a name="line.3665"></a>
<span class="sourceLineNo">3666</span><a name="line.3666"></a>
<span class="sourceLineNo">3667</span>        CSL(FTPClient parent, long idleTime, int maxWait) throws SocketException {<a name="line.3667"></a>
<span class="sourceLineNo">3668</span>            this.idle = idleTime;<a name="line.3668"></a>
<span class="sourceLineNo">3669</span>            this.parent = parent;<a name="line.3669"></a>
<span class="sourceLineNo">3670</span>            this.currentSoTimeout = parent.getSoTimeout();<a name="line.3670"></a>
<span class="sourceLineNo">3671</span>            parent.setSoTimeout(maxWait);<a name="line.3671"></a>
<span class="sourceLineNo">3672</span>        }<a name="line.3672"></a>
<span class="sourceLineNo">3673</span><a name="line.3673"></a>
<span class="sourceLineNo">3674</span>//        @Override<a name="line.3674"></a>
<span class="sourceLineNo">3675</span>        public void bytesTransferred(CopyStreamEvent event) {<a name="line.3675"></a>
<span class="sourceLineNo">3676</span>            bytesTransferred(event.getTotalBytesTransferred(), event.getBytesTransferred(), event.getStreamSize());<a name="line.3676"></a>
<span class="sourceLineNo">3677</span>        }<a name="line.3677"></a>
<span class="sourceLineNo">3678</span><a name="line.3678"></a>
<span class="sourceLineNo">3679</span>//        @Override<a name="line.3679"></a>
<span class="sourceLineNo">3680</span>        public void bytesTransferred(long totalBytesTransferred,<a name="line.3680"></a>
<span class="sourceLineNo">3681</span>                int bytesTransferred, long streamSize) {<a name="line.3681"></a>
<span class="sourceLineNo">3682</span>            long now = System.currentTimeMillis();<a name="line.3682"></a>
<span class="sourceLineNo">3683</span>            if (now - time &gt; idle) {<a name="line.3683"></a>
<span class="sourceLineNo">3684</span>                try {<a name="line.3684"></a>
<span class="sourceLineNo">3685</span>                    parent.__noop();<a name="line.3685"></a>
<span class="sourceLineNo">3686</span>                } catch (SocketTimeoutException e) {<a name="line.3686"></a>
<span class="sourceLineNo">3687</span>                    notAcked++;<a name="line.3687"></a>
<span class="sourceLineNo">3688</span>                } catch (IOException e) {<a name="line.3688"></a>
<span class="sourceLineNo">3689</span>                }<a name="line.3689"></a>
<span class="sourceLineNo">3690</span>                time = now;<a name="line.3690"></a>
<span class="sourceLineNo">3691</span>            }<a name="line.3691"></a>
<span class="sourceLineNo">3692</span>        }<a name="line.3692"></a>
<span class="sourceLineNo">3693</span><a name="line.3693"></a>
<span class="sourceLineNo">3694</span>        void cleanUp() throws IOException {<a name="line.3694"></a>
<span class="sourceLineNo">3695</span>            try {<a name="line.3695"></a>
<span class="sourceLineNo">3696</span>                while(notAcked-- &gt; 0) {<a name="line.3696"></a>
<span class="sourceLineNo">3697</span>                    parent.__getReplyNoReport();<a name="line.3697"></a>
<span class="sourceLineNo">3698</span>                }<a name="line.3698"></a>
<span class="sourceLineNo">3699</span>            } finally {<a name="line.3699"></a>
<span class="sourceLineNo">3700</span>                parent.setSoTimeout(currentSoTimeout);<a name="line.3700"></a>
<span class="sourceLineNo">3701</span>            }<a name="line.3701"></a>
<span class="sourceLineNo">3702</span>        }<a name="line.3702"></a>
<span class="sourceLineNo">3703</span><a name="line.3703"></a>
<span class="sourceLineNo">3704</span>    }<a name="line.3704"></a>
<span class="sourceLineNo">3705</span><a name="line.3705"></a>
<span class="sourceLineNo">3706</span>    /**<a name="line.3706"></a>
<span class="sourceLineNo">3707</span>     * Merge two copystream listeners, either or both of which may be null.<a name="line.3707"></a>
<span class="sourceLineNo">3708</span>     *<a name="line.3708"></a>
<span class="sourceLineNo">3709</span>     * @param local the listener used by this class, may be null<a name="line.3709"></a>
<span class="sourceLineNo">3710</span>     * @return a merged listener or a single listener or null<a name="line.3710"></a>
<span class="sourceLineNo">3711</span>     * @since 3.0<a name="line.3711"></a>
<span class="sourceLineNo">3712</span>     */<a name="line.3712"></a>
<span class="sourceLineNo">3713</span>    private CopyStreamListener __mergeListeners(CopyStreamListener local) {<a name="line.3713"></a>
<span class="sourceLineNo">3714</span>        if (local == null) {<a name="line.3714"></a>
<span class="sourceLineNo">3715</span>            return __copyStreamListener;<a name="line.3715"></a>
<span class="sourceLineNo">3716</span>        }<a name="line.3716"></a>
<span class="sourceLineNo">3717</span>        if (__copyStreamListener == null) {<a name="line.3717"></a>
<span class="sourceLineNo">3718</span>            return local;<a name="line.3718"></a>
<span class="sourceLineNo">3719</span>        }<a name="line.3719"></a>
<span class="sourceLineNo">3720</span>        // Both are non-null<a name="line.3720"></a>
<span class="sourceLineNo">3721</span>        CopyStreamAdapter merged = new CopyStreamAdapter();<a name="line.3721"></a>
<span class="sourceLineNo">3722</span>        merged.addCopyStreamListener(local);<a name="line.3722"></a>
<span class="sourceLineNo">3723</span>        merged.addCopyStreamListener(__copyStreamListener);<a name="line.3723"></a>
<span class="sourceLineNo">3724</span>        return merged;<a name="line.3724"></a>
<span class="sourceLineNo">3725</span>    }<a name="line.3725"></a>
<span class="sourceLineNo">3726</span><a name="line.3726"></a>
<span class="sourceLineNo">3727</span>    /**<a name="line.3727"></a>
<span class="sourceLineNo">3728</span>     * Enables or disables automatic server encoding detection (only UTF-8 supported).<a name="line.3728"></a>
<span class="sourceLineNo">3729</span>     * &lt;p&gt;<a name="line.3729"></a>
<span class="sourceLineNo">3730</span>     * Does not affect existing connections; must be invoked before a connection is established.<a name="line.3730"></a>
<span class="sourceLineNo">3731</span>     *<a name="line.3731"></a>
<span class="sourceLineNo">3732</span>     * @param autodetect If true, automatic server encoding detection will be enabled.<a name="line.3732"></a>
<span class="sourceLineNo">3733</span>     */<a name="line.3733"></a>
<span class="sourceLineNo">3734</span>    public void setAutodetectUTF8(boolean autodetect)<a name="line.3734"></a>
<span class="sourceLineNo">3735</span>    {<a name="line.3735"></a>
<span class="sourceLineNo">3736</span>        __autodetectEncoding = autodetect;<a name="line.3736"></a>
<span class="sourceLineNo">3737</span>    }<a name="line.3737"></a>
<span class="sourceLineNo">3738</span><a name="line.3738"></a>
<span class="sourceLineNo">3739</span>    /**<a name="line.3739"></a>
<span class="sourceLineNo">3740</span>     * Tells if automatic server encoding detection is enabled or disabled.<a name="line.3740"></a>
<span class="sourceLineNo">3741</span>     * @return true, if automatic server encoding detection is enabled.<a name="line.3741"></a>
<span class="sourceLineNo">3742</span>     */<a name="line.3742"></a>
<span class="sourceLineNo">3743</span>    public boolean getAutodetectUTF8()<a name="line.3743"></a>
<span class="sourceLineNo">3744</span>    {<a name="line.3744"></a>
<span class="sourceLineNo">3745</span>        return __autodetectEncoding;<a name="line.3745"></a>
<span class="sourceLineNo">3746</span>    }<a name="line.3746"></a>
<span class="sourceLineNo">3747</span><a name="line.3747"></a>
<span class="sourceLineNo">3748</span>    // DEPRECATED METHODS - for API compatibility only - DO NOT USE<a name="line.3748"></a>
<span class="sourceLineNo">3749</span><a name="line.3749"></a>
<span class="sourceLineNo">3750</span>    /**<a name="line.3750"></a>
<span class="sourceLineNo">3751</span>     * @deprecated use {@link #getSystemType()} instead<a name="line.3751"></a>
<span class="sourceLineNo">3752</span>     */<a name="line.3752"></a>
<span class="sourceLineNo">3753</span>    @Deprecated<a name="line.3753"></a>
<span class="sourceLineNo">3754</span>    public String getSystemName() throws IOException<a name="line.3754"></a>
<span class="sourceLineNo">3755</span>    {<a name="line.3755"></a>
<span class="sourceLineNo">3756</span>        if (__systemName == null &amp;&amp; FTPReply.isPositiveCompletion(syst())) {<a name="line.3756"></a>
<span class="sourceLineNo">3757</span>            __systemName = _replyLines.get(_replyLines.size() - 1).substring(4);<a name="line.3757"></a>
<span class="sourceLineNo">3758</span>        }<a name="line.3758"></a>
<span class="sourceLineNo">3759</span>        return __systemName;<a name="line.3759"></a>
<span class="sourceLineNo">3760</span>    }<a name="line.3760"></a>
<span class="sourceLineNo">3761</span>}<a name="line.3761"></a>
<span class="sourceLineNo">3762</span><a name="line.3762"></a>
<span class="sourceLineNo">3763</span>/* Emacs configuration<a name="line.3763"></a>
<span class="sourceLineNo">3764</span> * Local variables:        **<a name="line.3764"></a>
<span class="sourceLineNo">3765</span> * mode:             java  **<a name="line.3765"></a>
<span class="sourceLineNo">3766</span> * c-basic-offset:   4     **<a name="line.3766"></a>
<span class="sourceLineNo">3767</span> * indent-tabs-mode: nil   **<a name="line.3767"></a>
<span class="sourceLineNo">3768</span> * End:                    **<a name="line.3768"></a>
<span class="sourceLineNo">3769</span> */<a name="line.3769"></a>
<span class="sourceLineNo">3770</span>/* kate: indent-width 4; replace-tabs on; */<a name="line.3770"></a>




























































</pre>
</div>
</body>
</html>
